#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, a[N];
priority_queue<Element> q;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> a[i];
q.push((Element){a[i], i, i});
}
vector<pair<int,int>> Ans;
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 {
Ans.push_back(make_pair(mn, le.second + 1));
q.push((Element){mn + 1, le.first, le.second});
}
}
stack<pair<int,int>> s;
for(int i = (int)Ans.size() - 1; i >= 0; i--) {
s.push(Ans[i]);
}
int ptr = 0;
int need = k - (int)s.size();
for(int i = 0; i < n + k; i++) {
while(s.size()) {
if(s.top().second == i) {
if(need && s.top().first > 0) {
int x = s.top().first;
s.pop();
s.push(make_pair(x - 1, i));
s.push(make_pair(x - 1, i));
need--;
}
else {
cout << s.top().first << " ";
s.pop();
}
}
else {
break;
}
}
if(i < n) cout << a[i] << " ";
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:43:9: warning: unused variable 'ptr' [-Wunused-variable]
43 | int ptr = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
641 ms |
18248 KB |
Output is correct |
2 |
Correct |
654 ms |
18248 KB |
Output is correct |
3 |
Correct |
643 ms |
18372 KB |
Output is correct |
4 |
Correct |
651 ms |
18520 KB |
Output is correct |
5 |
Correct |
701 ms |
18232 KB |
Output is correct |
6 |
Correct |
637 ms |
18252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
670 ms |
20296 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
635 ms |
20296 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
651 ms |
20296 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
654 ms |
20424 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
645 ms |
20444 KB |
Unexpected end of file - int32 expected |
6 |
Correct |
672 ms |
20296 KB |
Output is correct |
7 |
Incorrect |
649 ms |
20280 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
668 ms |
20296 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
569 ms |
19276 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
207 ms |
9432 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
338 ms |
13656 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
4 ms |
384 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
4 ms |
384 KB |
Unexpected end of file - int32 expected |
14 |
Correct |
116 ms |
2296 KB |
Output is correct |