# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84903 | 2018-11-17T18:30:38 Z | ToadDaveski | Gift (IZhO18_nicegift) | C++14 | 668 ms | 32500 KB |
#include <bits/stdc++.h> #define ll long long #define fr first #define sc second using namespace std; vector <vector <pair <ll,ll> > > q; ll a[2000001]; map <ll,ll> poz; vector <ll> ans; int main() { ll n,k,i,j,ma=0; cin>>n>>k; ll sum=0,part; for(i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; ma=max(ma,a[i]); } part=sum/k; if (sum%k || part<ma ) { cout<<-1; return 0; } sum=0; vector <pair <ll,ll> > temp; for(i=1;i<=n;i++) { sum+=a[i]; if (sum>=part) { temp.push_back({a[i]-(sum-part),i}); q.push_back(temp); temp.clear(); sum=sum-part; if (sum) temp.push_back({sum,i}); } else { temp.push_back({a[i],i}); } } while(true) { ll mi=1e9; for(i=0;i<k;i++) mi=min(mi,q[i][poz[i]].fr); ans.push_back(mi); ll kol=0; for(i=0;i<k;i++) { ans.push_back(q[i][poz[i]].sc); q[i][poz[i]].fr-=mi; if (poz[i]<q[i].size() && !q[i][poz[i]].fr) { poz[i]++; if (poz[i]<q[i].size()) kol++; } } if (!kol) break; } ll toad=0; cout<<ans.size()/(k+1)<<endl; while(toad<ans.size()) { cout<<ans[toad]<<" "; if (((toad+1)%(k+1))==0) cout<<endl; toad++; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 372 KB | n=3 |
3 | Correct | 2 ms | 412 KB | n=3 |
4 | Correct | 2 ms | 460 KB | n=4 |
5 | Correct | 2 ms | 468 KB | n=4 |
6 | Correct | 2 ms | 604 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 372 KB | n=3 |
3 | Correct | 2 ms | 412 KB | n=3 |
4 | Correct | 2 ms | 460 KB | n=4 |
5 | Correct | 2 ms | 468 KB | n=4 |
6 | Correct | 2 ms | 604 KB | n=2 |
7 | Correct | 2 ms | 612 KB | n=5 |
8 | Correct | 2 ms | 632 KB | n=8 |
9 | Correct | 2 ms | 652 KB | n=14 |
10 | Correct | 2 ms | 652 KB | n=11 |
11 | Correct | 97 ms | 4160 KB | n=50000 |
12 | Correct | 91 ms | 4160 KB | n=50000 |
13 | Correct | 2 ms | 4160 KB | n=10 |
14 | Correct | 3 ms | 4160 KB | n=685 |
15 | Correct | 3 ms | 4160 KB | n=623 |
16 | Correct | 4 ms | 4160 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 372 KB | n=3 |
3 | Correct | 2 ms | 412 KB | n=3 |
4 | Correct | 2 ms | 460 KB | n=4 |
5 | Correct | 2 ms | 468 KB | n=4 |
6 | Correct | 2 ms | 604 KB | n=2 |
7 | Correct | 2 ms | 612 KB | n=5 |
8 | Correct | 2 ms | 632 KB | n=8 |
9 | Correct | 2 ms | 652 KB | n=14 |
10 | Correct | 2 ms | 652 KB | n=11 |
11 | Correct | 97 ms | 4160 KB | n=50000 |
12 | Correct | 91 ms | 4160 KB | n=50000 |
13 | Correct | 2 ms | 4160 KB | n=10 |
14 | Correct | 3 ms | 4160 KB | n=685 |
15 | Correct | 3 ms | 4160 KB | n=623 |
16 | Correct | 4 ms | 4160 KB | n=973 |
17 | Correct | 4 ms | 4160 KB | n=989 |
18 | Correct | 4 ms | 4160 KB | n=563 |
19 | Correct | 5 ms | 4160 KB | n=592 |
20 | Correct | 5 ms | 4160 KB | n=938 |
21 | Correct | 4 ms | 4160 KB | n=747 |
22 | Correct | 6 ms | 4160 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 668 ms | 32500 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 372 KB | n=3 |
3 | Correct | 2 ms | 412 KB | n=3 |
4 | Correct | 2 ms | 460 KB | n=4 |
5 | Correct | 2 ms | 468 KB | n=4 |
6 | Correct | 2 ms | 604 KB | n=2 |
7 | Correct | 2 ms | 612 KB | n=5 |
8 | Correct | 2 ms | 632 KB | n=8 |
9 | Correct | 2 ms | 652 KB | n=14 |
10 | Correct | 2 ms | 652 KB | n=11 |
11 | Correct | 97 ms | 4160 KB | n=50000 |
12 | Correct | 91 ms | 4160 KB | n=50000 |
13 | Correct | 2 ms | 4160 KB | n=10 |
14 | Correct | 3 ms | 4160 KB | n=685 |
15 | Correct | 3 ms | 4160 KB | n=623 |
16 | Correct | 4 ms | 4160 KB | n=973 |
17 | Correct | 4 ms | 4160 KB | n=989 |
18 | Correct | 4 ms | 4160 KB | n=563 |
19 | Correct | 5 ms | 4160 KB | n=592 |
20 | Correct | 5 ms | 4160 KB | n=938 |
21 | Correct | 4 ms | 4160 KB | n=747 |
22 | Correct | 6 ms | 4160 KB | n=991 |
23 | Incorrect | 668 ms | 32500 KB | Not all heaps are empty in the end |
24 | Halted | 0 ms | 0 KB | - |