# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168942 | abil | Gift (IZhO18_nicegift) | C++14 | 810 ms | 149160 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>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (1e18 + 12);
int a[N], b[N];
vector<pair<int,int > > vec[N];
vector<int > ans[N];
int res[N];
main()
{
int n, k, sum = 0, mx = 0;
scanf("%lld%lld", &n, &k);
for(int i = 1;i <= n; i++){
scanf("%lld", &a[i]);
sum += a[i];
mx = max(mx, a[i]);
}
if(sum % k != 0 || mx > sum / k){
cout << -1;
return 0;
}
int cur_sum = 0;
int sz = 0;
for(int i = 1;i <= n; i++){
cur_sum += a[i];
if(cur_sum >= sum / k){
int rem = cur_sum - sum / k;
cur_sum = rem;
vec[sz].pb({a[i] - rem, i});
sz++;
if(rem > 0){
vec[sz].pb({rem, i});
}
}
else{
vec[sz].pb({a[i], i});
}
}
int szofans = 1;
while(1){
int mn = INF;
for(int i = 0;i < sz; i++){
mn = min(mn, vec[i][b[i]].fr);
}
res[szofans] = mn;
bool f = false;
for(int i = 0;i < sz; i++){
vec[i][b[i]].fr -= mn;
ans[szofans].pb(vec[i][b[i]].sc);
if(vec[i][b[i]].fr == 0){
b[i]++;
if(b[i] == vec[i].size()){
f = true;
}
}
}
if(f){
break;
}
szofans++;
}
cout << szofans << endl;
for(int i = 1;i <= szofans; i++){
printf("%lld ", res[i]);
for(auto to : ans[i]){
printf("%lld ", to);
}
printf("\n");
}
}
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... |