This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
int n, k;
vector<pair<int, int>> ans;
vector<int> s;
void push(int x){
if(s.empty())
s.push_back(x);
else if(s.back() == x){
s.pop_back();
push(x+1);
}
else s.push_back(x);
}
void combine(){
ans.emplace_back(s.back(), 1);
--k;
push(s.back());
}
void try_push(int x){
while(!s.empty() && s.back() < x)
combine();
ans.emplace_back(x, 0);
push(x);
}
void print(pair<int, int> p){
if(!p.y || !k || p.x == 1){
cout << p.x << " ";
return;
}
--k;
print({p.x-1, 1});
print({p.x-1, 1});
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; ++i){
int x;
cin >> x;
try_push(x);
}
while(s.back() < 30)
combine();
for(auto el : ans)
print(el);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |