#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll int
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 2000004
#define INF 1e9+7
using namespace std;
ll n,k,ar[N],orig[N];
set < pi > s;
ll epomeno[N];
vector < pi > res;
void solve()
{
if((*s.begin()).first == 30)
return;
set < pi >::iterator it = s.begin();
pi cur = *it;
swap(cur.first,cur.second);
if(epomeno[cur.first] != n && ar[epomeno[cur.first]] == cur.second)
{
epomeno[cur.first] = epomeno[epomeno[cur.first]];
s.erase(s.begin());
}
else
res.push_back(cur);
s.erase(s.begin());
s.insert(mp(cur.second+1,cur.first));
ar[cur.first]++;
solve();
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> k;
rep(i,0,n)
{
cin >> ar[i];
orig[i] = ar[i];
epomeno[i] = i+1;
s.insert(mp(ar[i],i));
}
solve();
ll cur = 0;
ll sz = res.size();
ll start = 0;
while(sz < k)
{
if(res[start].second == 1)
{
start++;
continue;
}
res[start].second--;
res.push_back(res[start]);
sz++;
}
sort(res.begin(),res.end());
rep(i,0,n)
{
while(cur < k && res[cur].first <= i)
{
cout << res[cur].second << " ";
cur++;
}
cout << orig[i] << " ";
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
765 ms |
108280 KB |
Output is correct |
2 |
Correct |
863 ms |
108156 KB |
Output is correct |
3 |
Correct |
832 ms |
108180 KB |
Output is correct |
4 |
Correct |
784 ms |
108140 KB |
Output is correct |
5 |
Correct |
875 ms |
108152 KB |
Output is correct |
6 |
Correct |
778 ms |
108152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
859 ms |
108108 KB |
not a zalsequence |
2 |
Correct |
900 ms |
108280 KB |
Output is correct |
3 |
Incorrect |
853 ms |
108088 KB |
not a zalsequence |
4 |
Incorrect |
852 ms |
108152 KB |
not a zalsequence |
5 |
Correct |
862 ms |
108100 KB |
Output is correct |
6 |
Correct |
855 ms |
108280 KB |
Output is correct |
7 |
Correct |
863 ms |
108124 KB |
Output is correct |
8 |
Correct |
873 ms |
108208 KB |
Output is correct |
9 |
Incorrect |
831 ms |
95336 KB |
not a zalsequence |
10 |
Incorrect |
371 ms |
43808 KB |
not a zalsequence |
11 |
Incorrect |
552 ms |
64800 KB |
not a zalsequence |
12 |
Incorrect |
146 ms |
16212 KB |
not a zalsequence |
13 |
Incorrect |
140 ms |
16212 KB |
not a zalsequence |
14 |
Incorrect |
135 ms |
10452 KB |
not a zalsequence |