이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |