# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60730 | alenam0161 | Zalmoxis (BOI18_zalmoxis) | C++17 | 345 ms | 11536 KiB |
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>
void fl();
using namespace std;
const int N = 1000000+7;
int a[N];
stack<int> st;
vector<int> ans;
void rem(){
while(st.size()>=2){
int z=st.top();
st.pop();
if(z==st.top()){
st.pop();
st.push(z+1);
}
else{
st.push(z);
break;
}
}
}
int main(){
int n,k;
scanf("%d %d",&n,&k);
for(int i=0;i<n;++i){
scanf("%d",a+i);
}
st.push(a[0]);
ans.push_back(a[0]);
for(int i=1;i<n;++i){
if(a[i]>=st.top()){
while(a[i]>st.top()){
int x=st.top();
ans.push_back(x);
st.push(x);
rem();
k--;
}
ans.push_back(a[i]);
st.push(a[i]);
rem();
}
else{
ans.push_back(a[i]);
st.push(a[i]);
}
}
while(st.size()>1){
ans.push_back(st.top());
st.push(st.top());
rem();
k--;
}
int z=st.top();
while(k>0){
ans.push_back(z);
z++;
k--;
}
for(int i=0;i<ans.size();++i){
printf("%d ",ans[i]);
}
return 0;
}
void fl(){
freopen("input.txt","r",stdin);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |