#include <bits/stdc++.h>
using namespace std;
int steve[1000001],vf;
int steve1[1000001],vf1;
int v[1000001],v1[1000001];
vector <int> addie[1000001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k,i,j;
cin>>n>>k;
int rez=0;
v[0]=1e9;
for(i=1;i<=n;i++)
{
cin>>v[i];
rez+=(1<<v[i]);
v1[i]=v[i];
while(v[i]>v[steve[vf]])
{
addie[steve[vf]].push_back(v[steve[vf]]);
k--;
rez+=(1<<v[steve[vf]]);
v[steve[vf]]++;
while(vf&&v[steve[vf]]==v[steve[vf-1]])
{
v[steve[vf-1]]++;
vf--;
}
}
while(v[i]==v[steve[vf]])
{
v[i]++;
vf--;
}
steve[++vf]=i;
}
while(v[steve[vf]]!=30)
{
int min1=40;
for(i=1;i<=vf;i++)
min1=min(min1,v[steve[i]]);
vf1=0;
for(i=1;i<=vf;i++)
{
if(v[steve[i]]==min1)
{
k--;
v[steve[i]]++;
addie[steve[i]].push_back(min1);
rez+=(1<<min1);
}
while(v[steve[i]]==v[steve1[vf1]])
{
v[steve[i]]++;
vf1--;
}
steve1[++vf1]=steve[i];
}
vf=vf1;
for(i=1;i<=vf;i++)
steve[i]=steve1[i];
}
assert(rez==(1<<30));
rez=0;
for(i=1;i<=n;i++)
{
cout<<v1[i]<<" ";
//rez+=(1<<v1[i]);
for(auto it:addie[i])
{
if(k>=((1<<it)-1))
{
k-=((1<<it)-1);
for(j=1;j<=(1<<it);j++)
cout<<"0 ";
rez+=(1<<it);
continue;
}
else if(k)
{
int a=(int)log2(k)+1;
int newit=it-a;
//daca fac (1<<a) newit-uri, k-=((1<<a)-1)
k=((1<<a)-1)-k;
for(j=1;j<=(1<<a)-2*k;j++)
cout<<newit<<" ";
rez+=(1<<newit)*((1<<a)-2*k);
for(j=1;j<=k;j++)
cout<<newit+1<<" ";
rez+=(1<<(newit+1))*k;
k=0;
}
else
{
cout<<it<<" ";
rez+=(1<<it);
}
}
}
assert(rez==(1<<30));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
159 ms |
65996 KB |
Execution killed with signal 6 |
2 |
Runtime error |
167 ms |
65996 KB |
Execution killed with signal 6 |
3 |
Runtime error |
170 ms |
66260 KB |
Execution killed with signal 6 |
4 |
Runtime error |
160 ms |
66088 KB |
Execution killed with signal 6 |
5 |
Runtime error |
163 ms |
66004 KB |
Execution killed with signal 6 |
6 |
Runtime error |
160 ms |
66056 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
162 ms |
66040 KB |
Execution killed with signal 6 |
2 |
Runtime error |
162 ms |
66048 KB |
Execution killed with signal 6 |
3 |
Runtime error |
163 ms |
66212 KB |
Execution killed with signal 6 |
4 |
Runtime error |
170 ms |
66112 KB |
Execution killed with signal 6 |
5 |
Runtime error |
161 ms |
66084 KB |
Execution killed with signal 6 |
6 |
Runtime error |
161 ms |
66004 KB |
Execution killed with signal 6 |
7 |
Runtime error |
161 ms |
66048 KB |
Execution killed with signal 6 |
8 |
Runtime error |
168 ms |
66080 KB |
Execution killed with signal 6 |
9 |
Runtime error |
159 ms |
70228 KB |
Execution killed with signal 6 |
10 |
Runtime error |
113 ms |
60784 KB |
Execution killed with signal 6 |
11 |
Runtime error |
134 ms |
65848 KB |
Execution killed with signal 6 |
12 |
Runtime error |
74 ms |
50120 KB |
Execution killed with signal 6 |
13 |
Runtime error |
68 ms |
50044 KB |
Execution killed with signal 6 |
14 |
Runtime error |
72 ms |
50080 KB |
Execution killed with signal 6 |