# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548916 | cig32 | Distributing Candies (IOI21_candies) | C++17 | 4925 ms | 2097152 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 "candies.h"
#include "bits/stdc++.h"
using namespace std;
#include <cassert>
#include <cstdio>
#include <vector>
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size();
std::vector<int> s(n);
int q = l.size();
vector<long long> list[n];
for(int i=0; i<n; i++) {
list[i].push_back(1e15);
list[i].push_back(-1e15);
}
for(int i=0; i<q; i++) {
for(int j=l[i]; j<=r[i]; j++) list[j].push_back(v[i]);
}
for(int i=0; i<n; i++) {
int k = list[i].size();
long long ps[k];
ps[0] = list[i][0];
for(int j=1; j<k; j++) ps[j] = ps[j-1] + list[i][j];
long long smax[k], smin[k];
smax[k-1] = ps[k-1];
smin[k-1] = ps[k-1];
for(int j=k-2; j>=0; j--) {
smax[j] = max(smax[j+1], ps[j]);
smin[j] = min(smin[j+1], ps[j]);
}
int idx = -1;
long long optl, optr;
long long lb = 0, rb = c[i];
for(int j=0; j<k; j++) {
bool crash = 0;
if(ps[j] >= rb) {
long long q = ps[j] - rb;
rb += q;
lb += q;
crash = 1;
}
if(ps[j] <= lb) {
long long q = lb - ps[j];
rb -= q;
lb -= q;
crash = 1;
}
if(crash && smax[j] - smin[j] <= c[i]) {
idx = j;
optl = lb, optr = rb;
}
if(crash && smax[j] - smin[j] <= c[i]) {
idx = j;
optl = lb, optr = rb;
}
}
if(idx == -1) {
optl = 0, optr = c[i];
}
s[i] = ps[k-1] - optl;
}
return s;
}
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... |