Submission #1107892

#TimeUsernameProblemLanguageResultExecution timeMemory
1107892MuhammetGift (IZhO18_nicegift)C++17
30 / 100
34 ms4288 KiB
#include <bits/stdc++.h> using namespace std; #define sz(s) (int)s.size() #define ff first #define ss second int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector <int> a(n); multiset <pair<int,int>> s; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] == 0) continue; s.insert({a[i],i+1}); } vector <pair<int,int>> v1; vector <int> v; while(sz(s) >= k){ v1.clear(); for(int i = 0; i < k; i++){ v1.push_back(*(--s.end())); s.erase(--s.end()); } for(int i = 0; i < k; i++){ v1.back().ff--; if(v1.back().ff != 0) s.insert(v1.back()); v.push_back(v1.back().ss); v1.pop_back(); } } if(sz(s) > 0){ cout << -1; return 0; } reverse(v.begin(), v.end()); cout << sz(v)/k << "\n"; int x = sz(v)/k; while(x--){ cout << 1 << " "; int cnt = k; while(cnt--){ cout << v.back() << ' '; v.pop_back(); } cout << '\n'; } }
#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...