# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893246 | vjudge1 | Gift (IZhO18_nicegift) | C++17 | 558 ms | 524288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>
#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif
using namespace std ;
using ll = long long ;
#define int ll
int32_t main() {
cin.tie(0)->sync_with_stdio(false) ;
ll n , k ; cin >> n >> k ;
vector<ll> a(n) ;
for (ll &i : a) cin >> i ;
priority_queue<pair<ll,ll>> q ;
for (int i = 0 ; i < n ; i++) {
q.push({a[i], i}) ;
}
ll sum = accumulate(a.begin(), a.end(), 0ll) ;
if (sum % k || (q.size() && (sum / k) < q.top().first)) {
cout << -1 << "\n" ;
return 0 ;
}
vector<deque<ll>> res ;
while (q.size() >= k) {
deque<ll> cur ;
ll mn = LLONG_MAX ;
for (int i = 0 ; i < k ; i++) {
auto [value, ind] = q.top() ;
q.pop() ;
cur.push_back(ind) ;
mn = value ;
}
if (q.size()) mn = min(mn * 1ll, (sum / k) - q.top().first) ;
assert(mn >= 0) ;
sum -= k * mn ;
for (ll& i : cur) {
a[i] -= mn ;
if (a[i]> 0) {
q.push({a[i], i}) ;
}
i++ ;
}
cur.push_front(mn) ;
res.push_back(cur) ;
}
if (q.size()) {
cout << -1 ;
return 0 ;
}
reverse(res.begin(), res.end()) ;
cout << res.size() << "\n" ;
for (auto i : res) {
for (int j : i) cout << j << ' ' ;
cout << "\n" ;
}
return 0 ;
}
// 希望白银
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |