#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1e6 + 5;
struct Element {
int x, l, r;
bool operator<(Element other) const {
if(x == other.x) {
return l > other.l;
}
return x > other.x;
}
};
int n, k;
priority_queue<Element> q;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
q.push((Element){a[i], i, i});
}
int total = k;
vector<stack<int>> v(n + 1);
assert(false);
int ok = -1;
while(1) {
if(q.top().x == 30) break;
int mn = q.top().x;
pair<int,int> le = make_pair(q.top().l, q.top().r);
q.pop();
if(mn == q.top().x && le.second == q.top().l - 1) {
auto val = (Element){mn + 1, le.first, q.top().r};
q.pop();
q.push(val);
}
else {
v[0].push(mn);
ok = le.second + 1;
// v[le.second + 1].push(mn);
total--;
q.push((Element){mn + 1, le.first, le.second});
}
}
for(int i = 0; i <= n; i++) {
if(ok == i) {
stack<int> s;
// Reverse the stack to process in correct order
while(v[0].size()) {
s.push(v[0].top());
v[0].pop();
}
while(s.size()) {
while(total > 0 && s.top() > 0) {
total--;
int x = s.top();
s.pop();
s.push(x - 1);
s.push(x - 1);
}
cout << s.top() << " ";
s.pop();
}
}
if(i != n) cout << a[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
263 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Runtime error |
256 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Runtime error |
254 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Runtime error |
258 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Runtime error |
261 ms |
262148 KB |
Execution killed with signal 9 |
6 |
Runtime error |
248 ms |
262148 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
252 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Runtime error |
264 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Runtime error |
258 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Runtime error |
258 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Runtime error |
255 ms |
262148 KB |
Execution killed with signal 9 |
6 |
Runtime error |
256 ms |
262148 KB |
Execution killed with signal 9 |
7 |
Runtime error |
257 ms |
262148 KB |
Execution killed with signal 9 |
8 |
Runtime error |
260 ms |
262148 KB |
Execution killed with signal 9 |
9 |
Runtime error |
240 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Runtime error |
475 ms |
262144 KB |
Execution killed with signal 11 |
11 |
Runtime error |
202 ms |
262148 KB |
Execution killed with signal 9 |
12 |
Runtime error |
1 ms |
640 KB |
Execution killed with signal 11 |
13 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
14 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |