Submission #1032981

#TimeUsernameProblemLanguageResultExecution timeMemory
1032981phoenixGift (IZhO18_nicegift)C++17
0 / 100
314 ms84964 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int M = (1 << 20); int n, k; ll total; pair<ll, int> a[M]; vector<vector<ll>> res; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i].first; total += a[i].first; a[i].second = i + 1; } sort(a, a + n); if (total % k || a[n - 1].first > total / k) { cout << -1; return 0; } int l = 0, r = n - 1; while (l <= r) { cout << l << ' ' << r << '\n'; ll X = min(a[l].first, (total - k * a[r].first) / k); if (X) { res.push_back({X}); for (int i = l; i < l + k; i++) { a[i].first -= X; total -= X; res.back().push_back(a[i].second); } for (int i = r + 1; i < n; i++) { a[i].first -= X; res.back().push_back(a[i].second); } } if (a[r].first == total / k) { total -= a[r].first; r--, k--; } while (l <= r && !a[l].first) l++; } if (a[n - 1].first) { res.push_back({a[n - 1].first}); while (n && a[n - 1].first) res.back().push_back(a[--n].second); } cout << (int)res.size() << '\n'; for (auto v : res) { for (int c : v) cout << c << ' '; 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...