#include "bits/stdc++.h"
using namespace std;
#define int long long
int k;
vector <pair <int,int>> ans;
vector <int> a;
void decomp(int v) {
stack <int> st;
st.push(v);
while(k --) {
if(st.size() == 0) break;
int v = st.top();
st.pop();
if(v == 0) {
cout << 0 << " ";
k ++;
continue;
}
st.push(v-1);
st.push(v-1);
}
while(st.size()) cout << st.top() << " ", st.pop();
}
void f(int v) {
if(a.size() == 0) {
ans.push_back({v, 1});
return;
}
if(v == a.back()) {
ans.push_back({v,0});
a.pop_back();
return;
}
if(a.back() > v) {
ans.push_back({v,1});
return;
}
f(v-1);
f(v-1);
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, cnt = 0;
cin >> n >> k;
for(int i = 0; i < n; i ++) {
int x;
cin >> x;
a.push_back(x);
}
reverse(a.begin(), a.end());
f(30);
for(auto i : ans) k -= i.second;
for(auto i : ans) {
if(i.second == 0) cout << i.first << " ";
else if(k){
decomp(i.first);
}else cout << i.first << " ";
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:50:9: warning: unused variable 'cnt' [-Wunused-variable]
50 | int n, cnt = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
26428 KB |
Output is correct |
2 |
Correct |
104 ms |
26680 KB |
Output is correct |
3 |
Correct |
104 ms |
26116 KB |
Output is correct |
4 |
Correct |
105 ms |
26940 KB |
Output is correct |
5 |
Correct |
106 ms |
26160 KB |
Output is correct |
6 |
Correct |
104 ms |
26292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
302 ms |
34036 KB |
Expected EOF |
2 |
Correct |
105 ms |
26152 KB |
Output is correct |
3 |
Incorrect |
173 ms |
28976 KB |
Expected EOF |
4 |
Incorrect |
516 ms |
42024 KB |
Expected EOF |
5 |
Incorrect |
188 ms |
29208 KB |
Expected EOF |
6 |
Incorrect |
269 ms |
32688 KB |
Expected EOF |
7 |
Incorrect |
347 ms |
35756 KB |
Expected EOF |
8 |
Incorrect |
134 ms |
27180 KB |
Expected EOF |
9 |
Execution timed out |
1053 ms |
60972 KB |
Time limit exceeded |
10 |
Execution timed out |
1047 ms |
49788 KB |
Time limit exceeded |
11 |
Execution timed out |
1056 ms |
55980 KB |
Time limit exceeded |
12 |
Execution timed out |
1061 ms |
40972 KB |
Time limit exceeded |
13 |
Execution timed out |
1069 ms |
41228 KB |
Time limit exceeded |
14 |
Execution timed out |
1073 ms |
41060 KB |
Time limit exceeded |