Submission #378674

#TimeUsernameProblemLanguageResultExecution timeMemory
378674rk42745417Gift (IZhO18_nicegift)C++17
0 / 100
2101 ms406132 KiB
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using uint = uint32_t; using ld = long double; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const ll LINF = 2e18; const double EPS = 1e-9; #define EMT ios::sync_with_stdio(0); cin.tie(0); signed main() { EMT int n, k; cin >> n >> k; ll s = 0; vector<int> arr(n); priority_queue<pair<int, int>> pq; for(int i = 0; i < n; i++) cin >> arr[i], pq.push({arr[i], i}); for(int i = 0; i < n; i++) s += arr[i]; //if(*max_element(arr.begin(), arr.end()) == *min_element(arr.begin(), arr.end())) { //if( //} vector<pair<int, vector<int>>> ans; auto get = [&]() { if(pq.empty()) return -1; int w = pq.top().second; pq.pop(); return w; }; while(!pq.empty()) { vector<int> tmp(k); for(int i = 0; i < k; i++) tmp[i] = get(); if(tmp.back() < 0) return cout << "-1\n", 0; ans.push_back({1, tmp}); for(int a : tmp) { arr[a]--; if(arr[a]) pq.push({arr[a], a}); } } cout << ans.size() << '\n'; for(const auto &[x, y] : ans) { cout << x; for(int a : y) cout << ' ' << a; 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...