#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int n, k;
vector<int> res;
vector<int> st;
vector<array<int, 2>> aa;
void push(int x) {
while(st.size() && x == st.back()) {
st.pop_back(), x++;
}
st.push_back(x);
}
void uwu(int t) {
while(st.size() && st.back() < t) {
aa.push_back({st.back(), 1});
int x = st.back()+1;
st.pop_back();
push(x);
}
}
void ins(int x, int y) {
if(!y) {res.push_back(x); return;}
if(x > 1 && k) {
k--;
ins(x-1, 1);
ins(x-1, 1);
} else res.push_back(x);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
st.reserve(n+k);
for(int t, i = 0; i < n; i++) {
cin >> t;
uwu(t);
aa.push_back({t, 0});
push(t);
}
uwu(30);
k = n+k-aa.size();
for(auto [x, y] : aa) ins(x, y);
for(auto i : res) cout << i << " "; cout << endl;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:46:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
46 | for(auto i : res) cout << i << " "; cout << endl;
| ^~~
zalmoxis.cpp:46:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
46 | for(auto i : res) cout << i << " "; cout << endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
18388 KB |
Output is correct |
2 |
Correct |
195 ms |
18384 KB |
Output is correct |
3 |
Correct |
192 ms |
18512 KB |
Output is correct |
4 |
Correct |
191 ms |
18384 KB |
Output is correct |
5 |
Correct |
217 ms |
18292 KB |
Output is correct |
6 |
Correct |
197 ms |
18256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
18256 KB |
Output is correct |
2 |
Correct |
195 ms |
18256 KB |
Output is correct |
3 |
Correct |
199 ms |
18384 KB |
Output is correct |
4 |
Correct |
194 ms |
18384 KB |
Output is correct |
5 |
Correct |
198 ms |
18384 KB |
Output is correct |
6 |
Correct |
194 ms |
18256 KB |
Output is correct |
7 |
Correct |
191 ms |
18256 KB |
Output is correct |
8 |
Correct |
190 ms |
18400 KB |
Output is correct |
9 |
Correct |
188 ms |
17904 KB |
Output is correct |
10 |
Correct |
130 ms |
10112 KB |
Output is correct |
11 |
Correct |
150 ms |
15568 KB |
Output is correct |
12 |
Correct |
93 ms |
6364 KB |
Output is correct |
13 |
Correct |
95 ms |
6364 KB |
Output is correct |
14 |
Correct |
95 ms |
6364 KB |
Output is correct |