# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587244 | jakubd | Distributing Candies (IOI21_candies) | C++17 | 0 ms | 0 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;
#define int long long
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size(), q = (int)l.size();
vector<int> s;
if (n <= 2000 && q <= 2000) {
s.resize(n);
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
s[j] += v[i];
if (s[j] < 0) s[j] = 0;
if (s[j] > c[j]) s[j] = c[j];
}
}
} else {
s.resize(n + 1);
for (int i = 0; i < q; i++) {
s[l[i]] += v[i];
s[r[i] + 1] -= v[i];
}
for (int i = 0; i < n; i++) s[i + 1] += s[i];
vector<int> res(n);
for (int i = 0; i < n; i++) {
res[i] = min(s[i + 1], c[i]);
}
}
return s;
}