#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#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 3000004
#define INF 1e9+7
using namespace std;
ll n,k,ar[N],orig[N];
set < pi > s;
ll epomeno[N],proigoumeno[N];
vector < pi > res;
multiset < pi > varta;
multiset < pi > answers;
void solve()
{
if((*s.begin()).first == 30)
return;
set < pi >::iterator it = s.begin();
pi cur = *it;
swap(cur.first,cur.second);
// cout << cur.first << " " << cur.second << endl;
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(mp(cur.second,cur.first));
}
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;
proigoumeno[i+1] = i;
s.insert(mp(ar[i],i));
}
solve();
rep(i,0,res.size())
varta.insert(res[i]);
ll cur = 0;
ll sz = res.size();
res.clear();
while(sz < k)
{
pi f = *varta.begin();
varta.erase(varta.begin());
if(f.first == 0)
{
swap(f.first,f.second);
answers.insert(f);
continue;
}
f.first--;
varta.insert(f);
varta.insert(f);
sz++;
}
for(set < pi >::iterator it = varta.begin();it != varta.end();it++)
{
pi neo;
neo.first = it->second;
neo.second = it->first;
answers.insert(neo);
}
res.clear();
for(set < pi >::iterator it = answers.begin();it != answers.end();it++)
{
res.push_back(*it);
}
rep(i,0,n)
{
while(cur < k && res[cur].first <= i)
{
cout << res[cur].second << " ";
cur++;
}
cout << orig[i] << " ";
}
cout << endl;
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:13:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,a,b) for(int i = a;i < b;i++)
zalmoxis.cpp:73:9:
rep(i,0,res.size())
~~~~~~~~~~~~~~
zalmoxis.cpp:73:5: note: in expansion of macro 'rep'
rep(i,0,res.size())
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
852 ms |
159096 KB |
Output is correct |
2 |
Correct |
866 ms |
159160 KB |
Output is correct |
3 |
Correct |
863 ms |
159032 KB |
Output is correct |
4 |
Correct |
859 ms |
159196 KB |
Output is correct |
5 |
Correct |
919 ms |
159048 KB |
Output is correct |
6 |
Correct |
855 ms |
158980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
939 ms |
159152 KB |
not a zalsequence |
2 |
Correct |
930 ms |
159200 KB |
Output is correct |
3 |
Incorrect |
941 ms |
158892 KB |
not a zalsequence |
4 |
Incorrect |
953 ms |
159112 KB |
not a zalsequence |
5 |
Correct |
955 ms |
159012 KB |
Output is correct |
6 |
Execution timed out |
1016 ms |
159024 KB |
Time limit exceeded |
7 |
Execution timed out |
1029 ms |
158972 KB |
Time limit exceeded |
8 |
Incorrect |
956 ms |
159280 KB |
not a zalsequence |
9 |
Incorrect |
941 ms |
139436 KB |
not a zalsequence |
10 |
Incorrect |
754 ms |
100868 KB |
not a zalsequence |
11 |
Incorrect |
927 ms |
103324 KB |
not a zalsequence |
12 |
Incorrect |
660 ms |
80952 KB |
not a zalsequence |
13 |
Incorrect |
614 ms |
81048 KB |
not a zalsequence |
14 |
Incorrect |
589 ms |
80828 KB |
not a zalsequence |