Submission #300863

#TimeUsernameProblemLanguageResultExecution timeMemory
300863kaplanbarZalmoxis (BOI18_zalmoxis)C++14
40 / 100
680 ms34796 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int N = 2e6 + 5; struct Element { int x, l, r; bool operator<(Element other) const { if(x == other.x) { return l > other.l; } return x > other.x; } }; int n, k, a[N]; priority_queue<Element> q; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for(int i = 0; i < n; i++) { cin >> a[i]; q.push((Element){a[i], i, i}); } vector<pair<int,int>> Ans; while(1) { if(q.top().x == 30) break; int mn = q.top().x; pair<int,int> le = make_pair(q.top().l, q.top().r); q.pop(); if(mn == q.top().x && le.second == q.top().l - 1) { auto val = (Element){mn + 1, le.first, q.top().r}; q.pop(); q.push(val); } else { Ans.push_back(make_pair(mn, le.second + 1)); q.push((Element){mn + 1, le.first, le.second}); } } stack<pair<int,int>> s; int len = (int)Ans.size(); for(int i = len - 1; i >= 0; i--) { s.push(Ans[i]); } int need = k - (int)s.size(); for(int i = 0; i <= n; i++) { while(s.size()) { assert(s.top().second >= i); if(s.top().second == i) { while(need && s.top().first > 0) { int x = s.top().first; s.pop(); s.push(make_pair(x - 1, i)); s.push(make_pair(x - 1, i)); need--; } cout << s.top().first << " "; s.pop(); } else { break; } } if(i != n) { cout << a[i] << " "; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...