# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844072 | 2023-09-05T06:25:16 Z | Darren0724 | Gift (IZhO18_nicegift) | C++17 | 1885 ms | 109176 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define x first #define y second const int INF=1e18; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,k;cin>>n>>k; set<pair<int,int>> m; int total=0; for(int i=0;i<n;i++){ int p;cin>>p; total+=p; m.insert({p,i+1}); } if(total%k!=0){ cout<<-1<<endl; } vector<vector<int>> ans; while(m.size()>k+1){ pair<int,int> d=*m.begin(); int mn=d.x; m.erase(m.begin()); vector<pair<int,int>> v; v.push_back(d); for(int i=0;i<k-1;i++){ v.push_back(*m.rbegin()); m.erase(--m.end()); mn=min(mn,v.back().first-1); } vector<int> idx(k); for(int i=0;i<k;i++){ idx[i]=v[i].y; v[i].x-=mn; } idx.push_back(mn); reverse(idx.begin(),idx.end()); ans.push_back(idx); for(int i=0;i<k;i++){ if(v[i].x>0){ m.insert(v[i]); } } } total=0; for(auto p:m){ total+=p.x; } int need=total/k; vector<pair<int,int>> tmp(m.begin(),m.end()); int sz=tmp.size(); for(int i=0;i<sz;i++){ int d=need-tmp[i].x; if(d<0){ cout<<-1<<endl; return 0; } if(d==0){ continue; } vector<int> idx; for(int j=0;j<sz;j++){ if(i==j)continue; idx.push_back(tmp[j].second); } idx.push_back(d); reverse(idx.begin(),idx.end()); ans.push_back(idx); } cout<<ans.size()<<endl; for(auto &v:ans){ for(auto &j:v){ cout<<j<<' '; } cout<<endl; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Incorrect | 0 ms | 344 KB | Extra information in the output file |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Incorrect | 0 ms | 344 KB | Extra information in the output file |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Incorrect | 0 ms | 344 KB | Extra information in the output file |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1885 ms | 109176 KB | n=1000000 |
2 | Correct | 1551 ms | 78564 KB | n=666666 |
3 | Correct | 1056 ms | 51476 KB | n=400000 |
4 | Incorrect | 398 ms | 38100 KB | Jury has the answer but participant has not |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Incorrect | 0 ms | 344 KB | Extra information in the output file |
4 | Halted | 0 ms | 0 KB | - |