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>
using namespace std;
int n,k,v[1000010];
vector<int>ad[1000010];
vector<pair<int,int>>val[35];
void scrie(int val)
{
if(val==0||k==0)
{
cout<<val<<' ';
return;
}
--k;
scrie(val-1);
scrie(val-1);
return;
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>v[i];
val[v[i]].push_back({i,i});
}
for(int va=0;va<=29;++va)
{
sort(val[va].begin(),val[va].end());
int sz=val[va].size();
for(int i=0;i<sz;++i)
{
if(i+1==sz||val[va][i].second+1!=val[va][i+1].first)
{
--k;
ad[val[va][i].second].push_back(va);
val[va+1].push_back(val[va][i]);
}
else
{
val[va+1].push_back({val[va][i].first,val[va][i+1].second});
++i;
}
}
val[va].clear();
}
if(k<0)
return -1;
if(val[30].size()!=1)
return -1;
if(val[30][0].first!=1||val[30][0].second!=n)
return -1;
for(int i=1;i<=n;++i)
{
cout<<v[i]<<' ';
for(auto x:ad[i])
scrie(x);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |