Task: | Maalarit |
Sender: | fergusq |
Submission time: | 2016-10-03 23:00:31 +0300 |
Language: | C++ |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:17:35: error: parameter declared 'auto' sort(t.begin(), t.end(), [](auto i, auto j){ return i>j; }); ^ input/code.cpp:17:43: error: parameter declared 'auto' sort(t.begin(), t.end(), [](auto i, auto j){ return i>j; }); ^ input/code.cpp: In lambda function: input/code.cpp:17:54: error: 'i' was not declared in this scope sort(t.begin(), t.end(), [](auto i, auto j){ return i>j; }); ^ input/code.cpp:17:56: error: 'j' was not declared in this scope sort(t.begin(), t.end(), [](auto i, auto j){ return i>j; }); ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from input/code.cpp:3: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Comp...
Code
#include <iostream> #include <utility> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; vector<pair<int,int>> t; for (int i = 0; i < n; i++) { int k; cin >> k; t.push_back(make_pair(k,i)); } sort(t.begin(), t.end(), [](auto i, auto j){ return i>j; }); int m[999]; m[0]=0; int M=0; int T[n]; for (auto &p : t) { int k = p.first; int i = p.second; int mM = 0; while (mM < M) { if (i != 0 && T[i-1] == mM) { mM++; continue; } if (i != n-1 && T[i+1] == mM) { mM++; continue; } break; } if (mM == M) M++; T[i] = mM; if (m[mM] < k) m[mM] = k; } int s = 0; for (int i = 0; i <= M; i++) s += m[i]; cout << s << " " << M << endl; for (int i = 0; i < n; i++) cout << T[i] << " "; cout << endl; }