#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int n, k;
vector<pair<int, int> > ans;
multiset<int> st;
void f(int x, int depth){
// cout << x << ' ' << depth << '\n';
if(x < 0) assert(false);
int mn = (st.empty() ? INT_MAX : *st.begin());
if(x > mn){
f(x-1, depth + 1);
f(x-1, depth + 1);
}else{
ans.push_back({x, depth});
if(st.count(x))
st.erase(st.find(x));
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 0;i < n; i++){
int x; cin >> x;
st.insert(x);
}
f(30, 0);
if(ans.size() != (n + k)){
assert(false);
}else{
sort(all(ans), [&](pair<int, int> A, pair<int, int> B){
return A.ss < B.ss;
});
for(auto [x, y] : ans) cout << x << ' ';
}
return 0;
}
Compilation message
zalmoxis.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main(){
| ^~~~
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:35:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if(ans.size() != (n + k)){
| ~~~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1024 ms |
47404 KB |
Time limit exceeded |
2 |
Execution timed out |
1068 ms |
47400 KB |
Time limit exceeded |
3 |
Execution timed out |
1070 ms |
47408 KB |
Time limit exceeded |
4 |
Execution timed out |
1033 ms |
47656 KB |
Time limit exceeded |
5 |
Execution timed out |
1032 ms |
47400 KB |
Time limit exceeded |
6 |
Execution timed out |
1043 ms |
47400 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1032 ms |
47156 KB |
Time limit exceeded |
2 |
Execution timed out |
1050 ms |
47352 KB |
Time limit exceeded |
3 |
Execution timed out |
1051 ms |
47136 KB |
Time limit exceeded |
4 |
Execution timed out |
1042 ms |
47188 KB |
Time limit exceeded |
5 |
Execution timed out |
1073 ms |
47444 KB |
Time limit exceeded |
6 |
Execution timed out |
1071 ms |
47448 KB |
Time limit exceeded |
7 |
Execution timed out |
1062 ms |
47604 KB |
Time limit exceeded |
8 |
Execution timed out |
1041 ms |
47312 KB |
Time limit exceeded |
9 |
Execution timed out |
1014 ms |
38008 KB |
Time limit exceeded |
10 |
Execution timed out |
1054 ms |
14680 KB |
Time limit exceeded |
11 |
Execution timed out |
1070 ms |
24156 KB |
Time limit exceeded |
12 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
14 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |