# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169403 | 2019-12-20T08:40:38 Z | RafaelSus | Gift (IZhO18_nicegift) | C++14 | 695 ms | 64236 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; typedef long long ll; const ll inf=1e18+18ll; #define pb push_back ll n,k; ll a[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll S=0ll; cin>>n>>k; priority_queue<pair<ll,int>> q; for(int i=0;i<n;i++){ cin>>a[i]; q.push({a[i],i}); S+=a[i]; } if(S%k||q.top().first>S/k){cout<<"-1\n";return 0;} S/=k; vector<vector<int>> answ; ll cnt=0ll; while(q.top().first){ pair<ll,int>tmp[k]; //if(q.size()<k){cout<<"-1\n";return 0;} for(int i=0;i<k;i++){ tmp[i]=q.top(); q.pop(); } vector<int> an; ll mx=q.size()?q.top().first:0ll; ll x=min(tmp[k-1].first,S-mx); an.push_back(x);S-=x; for(int i=0;i<k;i++){ tmp[i].first-=x;q.push(tmp[i]); an.push_back(tmp[i].second+1); } cnt+=(ll)an.size(); //if(cnt>=3*1e6){cout<<"-1";return 0;} answ.push_back(an); } cout<<answ.size()<<'\n'; for(int i=0;i<answ.size();i++){ for(int j=0;j<answ[i].size();j++){ cout<<answ[i][j]<<' '; } cout<<'\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 2 ms | 380 KB | n=3 |
3 | Correct | 2 ms | 376 KB | n=3 |
4 | Correct | 2 ms | 376 KB | n=4 |
5 | Correct | 2 ms | 376 KB | n=4 |
6 | Correct | 2 ms | 376 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 2 ms | 380 KB | n=3 |
3 | Correct | 2 ms | 376 KB | n=3 |
4 | Correct | 2 ms | 376 KB | n=4 |
5 | Correct | 2 ms | 376 KB | n=4 |
6 | Correct | 2 ms | 376 KB | n=2 |
7 | Correct | 2 ms | 376 KB | n=5 |
8 | Correct | 2 ms | 376 KB | n=8 |
9 | Correct | 2 ms | 376 KB | n=14 |
10 | Correct | 2 ms | 376 KB | n=11 |
11 | Correct | 31 ms | 3696 KB | n=50000 |
12 | Correct | 28 ms | 3564 KB | n=50000 |
13 | Correct | 2 ms | 376 KB | n=10 |
14 | Correct | 3 ms | 376 KB | n=685 |
15 | Correct | 2 ms | 376 KB | n=623 |
16 | Correct | 3 ms | 376 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 2 ms | 380 KB | n=3 |
3 | Correct | 2 ms | 376 KB | n=3 |
4 | Correct | 2 ms | 376 KB | n=4 |
5 | Correct | 2 ms | 376 KB | n=4 |
6 | Correct | 2 ms | 376 KB | n=2 |
7 | Correct | 2 ms | 376 KB | n=5 |
8 | Correct | 2 ms | 376 KB | n=8 |
9 | Correct | 2 ms | 376 KB | n=14 |
10 | Correct | 2 ms | 376 KB | n=11 |
11 | Correct | 31 ms | 3696 KB | n=50000 |
12 | Correct | 28 ms | 3564 KB | n=50000 |
13 | Correct | 2 ms | 376 KB | n=10 |
14 | Correct | 3 ms | 376 KB | n=685 |
15 | Correct | 2 ms | 376 KB | n=623 |
16 | Correct | 3 ms | 376 KB | n=973 |
17 | Correct | 3 ms | 504 KB | n=989 |
18 | Correct | 2 ms | 376 KB | n=563 |
19 | Correct | 3 ms | 376 KB | n=592 |
20 | Correct | 3 ms | 376 KB | n=938 |
21 | Correct | 2 ms | 376 KB | n=747 |
22 | Correct | 2 ms | 376 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 695 ms | 64236 KB | Added number should be positive |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 2 ms | 380 KB | n=3 |
3 | Correct | 2 ms | 376 KB | n=3 |
4 | Correct | 2 ms | 376 KB | n=4 |
5 | Correct | 2 ms | 376 KB | n=4 |
6 | Correct | 2 ms | 376 KB | n=2 |
7 | Correct | 2 ms | 376 KB | n=5 |
8 | Correct | 2 ms | 376 KB | n=8 |
9 | Correct | 2 ms | 376 KB | n=14 |
10 | Correct | 2 ms | 376 KB | n=11 |
11 | Correct | 31 ms | 3696 KB | n=50000 |
12 | Correct | 28 ms | 3564 KB | n=50000 |
13 | Correct | 2 ms | 376 KB | n=10 |
14 | Correct | 3 ms | 376 KB | n=685 |
15 | Correct | 2 ms | 376 KB | n=623 |
16 | Correct | 3 ms | 376 KB | n=973 |
17 | Correct | 3 ms | 504 KB | n=989 |
18 | Correct | 2 ms | 376 KB | n=563 |
19 | Correct | 3 ms | 376 KB | n=592 |
20 | Correct | 3 ms | 376 KB | n=938 |
21 | Correct | 2 ms | 376 KB | n=747 |
22 | Correct | 2 ms | 376 KB | n=991 |
23 | Incorrect | 695 ms | 64236 KB | Added number should be positive |
24 | Halted | 0 ms | 0 KB | - |