# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
385603 | patrikpavic2 | Gift (IZhO18_nicegift) | C++17 | 1253 ms | 94620 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 <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#define X first
#define Y second
#define PB push_back
using namespace std;
const int N = 2e6 + 500;
typedef long long ll;
int n, k;
ll sm, A[N];
vector < pair < ll, int > > swp;
vector < ll > kv;
int main(){
scanf("%d%d", &n, &k);
for(int i = 1;i <= n;i++){
scanf("%lld", A + i);
sm += A[i];
}
if(sm % k != 0){
printf("-1\n");
return 0;
}
ll cik = (ll)sm / k;
for(int i = 1;i <= n;i++){
if(A[i] > cik){
printf("-1\n");
return 0;
}
}
ll cur = 0;
for(int i = 1;i <= n;i++){
if(cur + A[i] <= cik){
if(cur + A[i] < cik)
swp.PB({cur + A[i], -i});
swp.PB({cur, i}); kv.PB(cur);
cur = (cur + A[i]) % cik;
}
else{
swp.PB({cur, i}); kv.PB(cur);
swp.PB({0, i}); kv.PB(0);
swp.PB({A[i] - (cik - cur), -i});
cur = A[i] - (cik - cur);
}
}
sort(kv.begin(), kv.end());
kv.erase(unique(kv.begin(), kv.end()), kv.end());
printf("%d\n", (int)kv.size());
set < int > S;
sort(swp.begin(), swp.end());
for(int i = 0;i < (int)swp.size();){
int j = i;
while(i < (int)swp.size() && swp[i].X == swp[j].X){
if(swp[i].Y > 0) S.insert(swp[i].Y);
else S.erase(-swp[i].Y);
i++;
}
ll len = (i == (int)swp.size() ? cik : swp[i].X) - swp[j].X;
printf("%lld ", len);
for(int x : S)
printf("%d ", x);
printf("\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... |