Submission #1033027

#TimeUsernameProblemLanguageResultExecution timeMemory
1033027phoenixGift (IZhO18_nicegift)C++17
100 / 100
472 ms124512 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) { 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 (ll 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...