#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
int n, k;
stack<int> s;
vector<pair<int, int> > v;
void rastavi(int x)
{
while(len(s)) s.pop();
s.push(x);
while(len(s)&&k)
{
int w = s.top();
s.pop();
if(w==1) cout<<w<<" ";
else
{
k--;
s.push(w-1);
s.push(w-1);
}
}
while(len(s))
{
cout<<s.top()<<" ";
s.pop();
}
}
void sredi(int x)
{
while(len(s)&&x==s.top())
{
s.pop();
x++;
}
s.push(x);
}
int main()
{
ios
cin>>n>>k;
for(int i = 1;i<=n+1;i++)
{
int x;
if(i==n+1) x = 30;
else cin>>x;
while(len(s)&&x>s.top())
{
//cout<<s.top()<<" "<<x<<endl;
v.pb({s.top(), 1});
sredi(s.top());
k--;
}
sredi(x);
if(i<=n) v.pb({x, 0});
}
for(auto x : v)
{
if(x.second==0) cout<<x.first<<" ";
else rastavi(x.first);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
10448 KB |
Output is correct |
2 |
Correct |
175 ms |
10576 KB |
Output is correct |
3 |
Correct |
178 ms |
10448 KB |
Output is correct |
4 |
Correct |
177 ms |
10576 KB |
Output is correct |
5 |
Correct |
174 ms |
10448 KB |
Output is correct |
6 |
Correct |
177 ms |
10448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
10448 KB |
Output is correct |
2 |
Correct |
175 ms |
10576 KB |
Output is correct |
3 |
Correct |
176 ms |
10384 KB |
Output is correct |
4 |
Correct |
175 ms |
10448 KB |
Output is correct |
5 |
Correct |
175 ms |
10448 KB |
Output is correct |
6 |
Correct |
175 ms |
10576 KB |
Output is correct |
7 |
Correct |
177 ms |
10484 KB |
Output is correct |
8 |
Correct |
180 ms |
10536 KB |
Output is correct |
9 |
Correct |
166 ms |
9936 KB |
Output is correct |
10 |
Correct |
128 ms |
10716 KB |
Output is correct |
11 |
Correct |
142 ms |
8672 KB |
Output is correct |
12 |
Correct |
106 ms |
12396 KB |
Output is correct |
13 |
Correct |
105 ms |
12396 KB |
Output is correct |
14 |
Correct |
93 ms |
2412 KB |
Output is correct |