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 int long long
using namespace std;
signed main () {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k; cin >> n >> k;
vector<int> S (n);
for (int i = 0; i < n; i++) cin >> S[i];
assert(k == 1);
stack<int> nums;
int insert = -1;
for (int i = 0; i < n && insert == -1; i++) {
int cur = S[i];
while (!nums.empty()) {
int top = nums.top();
//cerr << cur << " " << top << " " << i << "\n";
if (cur == top) {
cur++;
nums.pop();
} else if (cur > top) {
insert = i;
break;
} else break;
}
if (insert != -1) break;
nums.push(cur);
}
if (insert == -1) insert = n-1;
for (int i = 0; i < n; i++) {
if (i == insert) cout << nums.top() << " ";
cout << S[i] << " ";
}
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |