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;
vector<int> distribute_candies(
vector<int> c, vector<int> l,
vector<int> r, vector<int> v
) {
int n = c.size();
int q = v.size();
if (q <= 2000 && n <= 2000) {
vector<int> s(n);
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
s[j] = max(min(s[j] + v[i], c[j]), 0);
}
}
return s;
}
bool pos = true;
for (int i = 0; i < n; i++) {
if (c[i] < 0) {
pos = false;
break;
}
}
if (pos) {
// difference array
vector<long long> d(n + 1);
for (int i = 0; i < q; i++) {
d[l[i]] += (long long)v[i];
d[r[i] + 1] -= (long long)v[i];
}
vector<long long> s(n);
s[0] = d[0];
for (int i = 1; i < n; i++) {
s[i] = s[i - 1] + d[i];
}
for (int i = 0; i < n; i++) {
s[i] = min(s[i], (long long)c[i]);
// s[i] = max(s[i], 0LL);
}
vector<int> res(n);
for (int i = 0; i < n; i++) {
res[i] = s[i];
}
return res;
}
vector<int> s(n, 0);
return s;
}
# | 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... |