# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
341540 | 2020-12-30T00:18:04 Z | ivan_tudor | Gift (IZhO18_nicegift) | C++14 | 119 ms | 34064 KB |
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5; priority_queue <pair<long long, int>> pq; long long v[N]; vector<vector<int>> ans; vector<long long> ansx; int main() { freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n, k; cin>>n>>k; long long sum = 0, mx = 0; for(int i=1;i<=n;i++){ cin>>v[i]; pq.push({v[i], i}); sum+=v[i]; mx = max(mx, v[i]); } if(sum%k!=0 || sum/k < mx ){ cout<<"-1\n"; return 0; } long long op = sum / k; while(pq.size()){ vector<int> aux; for(int i = 1 ;i <=k;i++){ aux.push_back(pq.top().second); pq.pop(); } long long mn = v[aux[aux.size() - 1]]; long long nxt = 0; if(pq.size()) nxt = pq.top().first; long long newX = min(mn, op - nxt); op -= newX; ansx.push_back(newX); ans.push_back(aux); for(auto x : aux){ v[x] -= newX; if(v[x]) pq.push({v[x], x}); } } cout<<ans.size()<<"\n"; for(int i= 0; i<ans.size();i++){ cout<<ansx[i]<<" "; for(auto x : ans[i]) cout<<x<<" "; cout<<"\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 115 ms | 34064 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 115 ms | 34064 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 115 ms | 34064 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 119 ms | 34064 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 115 ms | 34064 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |