# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334617 | 2020-12-09T15:06:12 Z | beksultan04 | Gift (IZhO18_nicegift) | C++14 | 247 ms | 75220 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define OK puts("OK"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define pb push_back #define endi puts(""); const int N = 1e6+12,INF=1e9+7; vector <pii> v[N]; vector <int> ans[N]; int q[N]; main(){ int n,k,i,j,sum=0,cnt=0,mx=0,aa=0; scan2(n,k) for (i=0;i<n;++i) scan1(q[i]); for (i=0;i<n;++i){ mx = max(mx,q[i]); sum+=q[i]; } if (mx*k > sum || sum%k){ cout <<-1; ret 0; } else { int sz = sum/k,c=0; for (i=0;i<n;++i){ if (c+q[i] >= sz){ int x = c+q[i]-sz; v[cnt++].pb({q[i]-x,i+1}); c = (q[i]+c)%sz; v[cnt].pb({c,i+1}); } else { c+=q[i]; v[cnt].pb({q[i],i+1}); } } bool f=1; while (f){ f=0; int mn = INF; for (i=0;i<k;++i){ mn = min(mn,v[i].back().fr); } ans[aa].pb(mn); for (i=0;i<k;++i){ pii x = v[i].back(); v[i].pop_back(); x.fr -= mn; ans[aa].pb(x.sc); if (x.fr > 0){ v[i].pb(x); f=1; } } aa++; } cout <<aa<<"\n"; for (i=0;i<aa;++i){ for (j=0;j<ans[i].size();++j){ cout <<ans[i][j]<<" "; } endi } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 33 ms | 47280 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Incorrect | 33 ms | 47340 KB | Not all heaps are empty in the end |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 33 ms | 47280 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Incorrect | 33 ms | 47340 KB | Not all heaps are empty in the end |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 33 ms | 47280 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Incorrect | 33 ms | 47340 KB | Not all heaps are empty in the end |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 247 ms | 75220 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 33 ms | 47280 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Incorrect | 33 ms | 47340 KB | Not all heaps are empty in the end |
5 | Halted | 0 ms | 0 KB | - |