Submission #844068

#TimeUsernameProblemLanguageResultExecution timeMemory
844068GrandTiger1729Gift (IZhO18_nicegift)C++17
30 / 100
329 ms66828 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, K; cin >> n >> K; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; priority_queue<pair<int, int>> pq; for (int i = 0; i < n; i++) pq.emplace(a[i], i); vector<vector<int>> ans; while (pq.size()) { vector<pair<int, int>> res; for (int i = 0; i < K; i++) { if (pq.empty()) { cout << -1 << '\n'; return 0; } auto x = pq.top(); pq.pop(); x.first--; res.push_back(x); } ans.emplace_back(); for (int i = 0; i < K; i++) { ans.back().push_back(res[i].second); if (res[i].first > 0) pq.push(res[i]); } } cout << ans.size() << '\n'; for (auto &vec : ans) { cout << 1 << ' '; for (int j = 0; j < K; j++) cout << vec[j] + 1 << " \n"[j == K - 1]; } return 0; }
#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...