#include <bits/stdc++.h>
using namespace std;
void solve() {
// ifstream cin ("zalmoxis.in");
// ofstream cout ("zalmoxis.out");
int n, k;
cin >> n >> k;
vector<int> st = {(int) 1e9};
vector<int> a(n), ans;
int done = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == st.back()) {
st.push_back(a[i]);
while (st.size() > 1 && st.back() == st[st.size() - 2]) {
st.pop_back();
st.back()++;
}
} else if (a[i] > st.back()) {
while (a[i] >= st.back()) {
ans.push_back(st.back());
++done;
st.back()++;
while (st.size() > 1 && st.back() == st[st.size() - 2]) {
st.pop_back();
st.back()++;
}
}
--done;
ans.pop_back();
} else {
st.push_back(a[i]);
}
ans.push_back(a[i]);
}
while (st.size() != 2) {
ans.push_back(st.back());
st.push_back(st.back());
++done;
while (st.size() > 1 && st.back() == st[st.size() - 2]) {
st.pop_back();
st.back()++;
}
}
for (int it = st[1]; it < st[1] + k - done; ++it) {
ans.push_back(it);
}
assert(done == k);
for (int x : ans) cout << x << ' ';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
10316 KB |
Output is correct |
2 |
Correct |
133 ms |
10324 KB |
Output is correct |
3 |
Correct |
131 ms |
10308 KB |
Output is correct |
4 |
Correct |
131 ms |
10364 KB |
Output is correct |
5 |
Correct |
135 ms |
10328 KB |
Output is correct |
6 |
Correct |
133 ms |
10280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
73 ms |
16572 KB |
Execution killed with signal 6 |
2 |
Runtime error |
70 ms |
16600 KB |
Execution killed with signal 6 |
3 |
Runtime error |
72 ms |
16532 KB |
Execution killed with signal 6 |
4 |
Runtime error |
77 ms |
16560 KB |
Execution killed with signal 6 |
5 |
Runtime error |
73 ms |
16668 KB |
Execution killed with signal 6 |
6 |
Runtime error |
72 ms |
16612 KB |
Execution killed with signal 6 |
7 |
Runtime error |
73 ms |
16588 KB |
Execution killed with signal 6 |
8 |
Runtime error |
76 ms |
16688 KB |
Execution killed with signal 6 |
9 |
Runtime error |
61 ms |
15036 KB |
Execution killed with signal 6 |
10 |
Runtime error |
33 ms |
11068 KB |
Execution killed with signal 6 |
11 |
Runtime error |
42 ms |
12596 KB |
Execution killed with signal 6 |
12 |
Runtime error |
11 ms |
8648 KB |
Execution killed with signal 6 |
13 |
Runtime error |
12 ms |
8648 KB |
Execution killed with signal 6 |
14 |
Runtime error |
11 ms |
8712 KB |
Execution killed with signal 6 |