# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
726741 |
2023-04-19T09:53:42 Z |
fdnfksd |
Gift (IZhO18_nicegift) |
C++14 |
|
822 ms |
96456 KB |
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,k,a[maxN];
void solve()
{
cin >> n >> k;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
sum+=a[i];
}
// if(sum<=1e5)
{
priority_queue<pli> pq;
for(int i=1;i<=n;i++) pq.push({a[i],i});
vector<pli> vc;
vc.resize(k);
vector<vector<ll>> ans;
while(pq.size()>=k)
{
vector<ll> vd;
ll mn=inf;
for(int i=0;i<k;i++)
{
vc[i]=pq.top();
pq.pop();
mn=min(mn,vc[i].fi);
}
ll ers=mn;
if(pq.size()>0) ers=min(ers,sum/k-pq.top().fi);
sum-=k*ers;
vd.pb(ers);
for(int i=0;i<k;i++)
{
vc[i].fi-=ers;
if(vc[i].fi>0) pq.push(vc[i]);
vd.pb(vc[i].se);
}
ans.pb(vd);
}
if(sum==0)
{
cout << ans.size()<<'\n';
for(auto vec:ans)
{
for(auto zz:vec) cout << zz<<' ';
cout << '\n';
}
}
else cout << -1;
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
nicegift.cpp: In function 'void solve()':
nicegift.cpp:30:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
30 | while(pq.size()>=k)
| ~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
328 KB |
n=4 |
5 |
Correct |
1 ms |
324 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
328 KB |
n=4 |
5 |
Correct |
1 ms |
324 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
21 ms |
3704 KB |
n=50000 |
12 |
Correct |
23 ms |
3400 KB |
n=50000 |
13 |
Correct |
1 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
328 KB |
n=4 |
5 |
Correct |
1 ms |
324 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
21 ms |
3704 KB |
n=50000 |
12 |
Correct |
23 ms |
3400 KB |
n=50000 |
13 |
Correct |
1 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
328 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
458 ms |
65812 KB |
n=1000000 |
2 |
Correct |
284 ms |
40604 KB |
n=666666 |
3 |
Correct |
160 ms |
21960 KB |
n=400000 |
4 |
Correct |
107 ms |
14256 KB |
n=285714 |
5 |
Correct |
7 ms |
1368 KB |
n=20000 |
6 |
Correct |
65 ms |
8936 KB |
n=181818 |
7 |
Correct |
4 ms |
956 KB |
n=10000 |
8 |
Correct |
3 ms |
724 KB |
n=6666 |
9 |
Correct |
2 ms |
468 KB |
n=4000 |
10 |
Correct |
3 ms |
596 KB |
n=2857 |
11 |
Correct |
1 ms |
468 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
328 KB |
n=4 |
5 |
Correct |
1 ms |
324 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
21 ms |
3704 KB |
n=50000 |
12 |
Correct |
23 ms |
3400 KB |
n=50000 |
13 |
Correct |
1 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
328 KB |
n=991 |
23 |
Correct |
458 ms |
65812 KB |
n=1000000 |
24 |
Correct |
284 ms |
40604 KB |
n=666666 |
25 |
Correct |
160 ms |
21960 KB |
n=400000 |
26 |
Correct |
107 ms |
14256 KB |
n=285714 |
27 |
Correct |
7 ms |
1368 KB |
n=20000 |
28 |
Correct |
65 ms |
8936 KB |
n=181818 |
29 |
Correct |
4 ms |
956 KB |
n=10000 |
30 |
Correct |
3 ms |
724 KB |
n=6666 |
31 |
Correct |
2 ms |
468 KB |
n=4000 |
32 |
Correct |
3 ms |
596 KB |
n=2857 |
33 |
Correct |
1 ms |
468 KB |
n=2000 |
34 |
Correct |
14 ms |
2292 KB |
n=23514 |
35 |
Correct |
14 ms |
2276 KB |
n=23514 |
36 |
Correct |
1 ms |
328 KB |
n=940 |
37 |
Correct |
0 ms |
212 KB |
n=2 |
38 |
Correct |
35 ms |
5548 KB |
n=100000 |
39 |
Correct |
35 ms |
5608 KB |
n=100000 |
40 |
Correct |
1 ms |
212 KB |
n=10 |
41 |
Correct |
1 ms |
340 KB |
n=100 |
42 |
Correct |
3 ms |
520 KB |
n=1000 |
43 |
Correct |
556 ms |
86772 KB |
n=1000000 |
44 |
Correct |
822 ms |
96456 KB |
n=1000000 |
45 |
Correct |
496 ms |
63820 KB |
n=666666 |
46 |
Correct |
308 ms |
36216 KB |
n=400000 |
47 |
Correct |
9 ms |
1108 KB |
n=2336 |
48 |
Correct |
532 ms |
54716 KB |
n=285714 |
49 |
Correct |
476 ms |
45212 KB |
n=181818 |
50 |
Correct |
24 ms |
3016 KB |
n=40000 |
51 |
Correct |
12 ms |
1620 KB |
n=20000 |
52 |
Correct |
8 ms |
984 KB |
n=10000 |
53 |
Correct |
47 ms |
4400 KB |
n=6666 |
54 |
Correct |
4 ms |
596 KB |
n=4000 |
55 |
Correct |
181 ms |
16244 KB |
n=2857 |
56 |
Correct |
3 ms |
596 KB |
n=2000 |