제출 #1125803

#제출 시각아이디문제언어결과실행 시간메모리
1125803boris_7Gift (IZhO18_nicegift)C++20
30 / 100
257 ms51248 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n,k; cin>>n>>k; vector<int>v(n); int sum = 0; multiset<pair<int,int>>ms; for(int i=0;i<n;i++){ cin>>v[i]; ms.insert({v[i],i}); sum+=v[i]; } vector<vector<pair<int,int>>>ans; if(sum%k) cout<<"-1\n"; else{ while(ms.size()>=k){ vector<pair<int,int>>z; for(int i = 0;i<k;i++){ pair<int,int> a = *ms.rbegin(); ms.erase(ms.find(a)); a.first--; z.push_back(a); } ans.push_back(z); for(pair<int,int> &i:z){ if(i.first) ms.insert(i); } } if(ms.size() && ms.size()<k) cout<<-1<<endl; else{ cout<<ans.size()<<endl; for(auto &i:ans){ cout<<1<<" "; for(pair<int,int> &j:i) cout<<j.second+1<<" "; cout<<endl; } } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); // ll t;cin>>t;while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...