#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(1);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
690 ms |
18380 KB |
Output is correct |
2 |
Correct |
683 ms |
18392 KB |
Output is correct |
3 |
Correct |
677 ms |
18252 KB |
Output is correct |
4 |
Correct |
629 ms |
18252 KB |
Output is correct |
5 |
Correct |
644 ms |
18208 KB |
Output is correct |
6 |
Correct |
638 ms |
18240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
636 ms |
18380 KB |
not a zalsequence |
2 |
Incorrect |
667 ms |
18276 KB |
not a zalsequence |
3 |
Incorrect |
680 ms |
18328 KB |
not a zalsequence |
4 |
Incorrect |
648 ms |
18380 KB |
not a zalsequence |
5 |
Incorrect |
671 ms |
18252 KB |
not a zalsequence |
6 |
Incorrect |
646 ms |
18252 KB |
not a zalsequence |
7 |
Incorrect |
706 ms |
18212 KB |
not a zalsequence |
8 |
Incorrect |
697 ms |
18252 KB |
not a zalsequence |
9 |
Incorrect |
609 ms |
15964 KB |
not a zalsequence |
10 |
Incorrect |
262 ms |
7784 KB |
not a zalsequence |
11 |
Incorrect |
390 ms |
10972 KB |
not a zalsequence |
12 |
Incorrect |
89 ms |
2296 KB |
not a zalsequence |
13 |
Incorrect |
88 ms |
2296 KB |
not a zalsequence |
14 |
Correct |
92 ms |
2296 KB |
Output is correct |