Submission #994384

#TimeUsernameProblemLanguageResultExecution timeMemory
994384tch1cherinGift (IZhO18_nicegift)C++17
30 / 100
1675 ms524288 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, K; cin >> N >> K; vector<long long> A(N); priority_queue<pair<long long, int>> Q; long long sum = 0; for (int i = 0; i < N; i++) { cin >> A[i]; Q.push({A[i], i}); sum += A[i]; } vector<vector<long long>> answer; answer.reserve(3000000); vector<int> pos; while ((int)Q.size() >= K) { pos.clear(); long long val = numeric_limits<int>::max(); for (int i = 0; i < K; i++) { val = min(val, Q.top().first); pos.push_back(Q.top().second); Q.pop(); } if (!Q.empty()) { val = min(val, sum / K - Q.top().first); } answer.push_back({val}); for (int i : pos) { answer.back().push_back(1 + i); if ((A[i] -= val) > 0) { Q.push({A[i], i}); } sum -= val; } } if (Q.empty()) { cout << answer.size() << "\n"; for (auto &op : answer) { for (int i = 0; i <= K; i++) { cout << op[i] << " \n"[i == K]; } } } else { cout << "-1\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...