# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881307 | dimashhh | Gift (IZhO18_nicegift) | C++17 | 639 ms | 172940 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>
using namespace std;
typedef long long ll;
const int N = 1e6 + 1;
#define int long long
ll n,k;
ll a[N];
priority_queue<pair<ll,ll>> st;
vector<pair<vector<int>,int>> res(N * 3);
ll s =0;
void test(){
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
st.push({a[i],i});
s += a[i];
}
if(s % k || (st.top()).first > s / k){
cout << -1;
return;
}
int it = 1;
while(!st.empty()){
vector<int> f;
ll oo;
for(int i = 1;i <= k;i++){
auto [x,y] = st.top();
st.pop();
oo = x;
f.push_back(y);
}
if(st.size()){
ll val = (st.top()).first;
oo = min(oo,(-val * k + s) / k);
}
s -= k * oo;
res[it] = {f,oo};
it++;
for(auto j:f){
a[j] -= oo;
if(a[j]){
st.push({a[j],j});
}
}
}
cout << it - 1 << '\n';
for(int f = 1;f < it;f++){
cout << res[f].second << ' ';
for(auto j:res[f].first)
cout << j << ' ';
cout << '\n';
}
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while(T--)
test();
}
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... |