This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |