Submission #345971

#TimeUsernameProblemLanguageResultExecution timeMemory
345971MladenPZalmoxis (BOI18_zalmoxis)C++17
100 / 100
180 ms13276 KiB
#include <bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second #define pb push_back #define PRINT(x) cerr<<#x<<'='<<x<<endl; using namespace std; int N, K; vector<pii> rez; vector<int> tmp; void rastavi(int X) { tmp.clear(); tmp.pb(X); while(K && !tmp.empty()) { int bck = tmp.back(); tmp.pop_back(); if(bck == 1) { cout << bck << ' '; } else { K--; tmp.pb(bck-1); tmp.pb(bck-1); } } while(!tmp.empty()) { int bck = tmp.back(); tmp.pop_back(); cout << bck << ' '; } } void ubaci(int x) { while(!tmp.empty() && x == tmp.back()) { x++; tmp.pop_back(); } tmp.pb(x); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; for(int i = 1; i <= N+1; i++) { int x; if(i <= N) cin >> x; else x = 30; while(!tmp.empty() && x > tmp.back()) { rez.pb({tmp.back(), 1}); ubaci(tmp.back()); K--; } ubaci(x); if(i <= N) rez.pb({x, 0}); } for(auto x : rez) { if(x.se == 0) { cout << x.fi << ' '; } else { rastavi(x.fi); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...