# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893261 | vjudge1 | Gift (IZhO18_nicegift) | C++17 | 728 ms | 98112 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 = 0 ;
for (ll i : a) sum += i ;
if (sum % k) {
cout << -1 ;
return 0 ;
}
if (sum / k < q.top().first) {
cout << -1 ;
return 0 ;
}
vector<vector<ll>> res ;
while (q.size() >= k) {
deque<ll> cur ;
ll mn = INT_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) ;
sum -= k * mn ;
vector<ll> vec ;
vec.push_back(mn) ;
for (ll& i : cur) {
a[i] -= mn ;
vec.push_back(i + 1) ;
if (a[i]> 0) {
q.push({a[i], i}) ;
}
}
res.push_back(vec) ;
}
if (sum) {
cout << -1 ;
return 0 ;
}
reverse(res.begin(), res.end()) ;
cout << (ll)res.size() << "\n" ;
if (res.size()) {
for (auto i : res) {
for (auto x : i) {
cout << x << ' ' ;
}
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... |