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;
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(), q = v.size();
if (n <= 2000) {
vector<int> ans(n);
for (int i = 0; i < q; ++i) {
for (int j = l[i]; j <= r[i]; ++j) {
if (v[i] > 0)
ans[j] = min(c[j], ans[j] + v[i]);
else
ans[j] = max(0, ans[j] + v[i]);
}
}
return ans;
}
if (*min_element(v.begin(), v.end()) > 0) {
vector<int64_t> s(n + 1);
vector<int> ans(n);
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] += (i ? s[i - 1] : 0);
ans[i] = (s[i] <= c[i] ? s[i] : c[i]);
}
return ans;
}
int cur = 0;
for (int i = 0; i < q; ++i) {
if (v[i] > 0)
cur = min(c[0], cur + v[i]);
else
cur = max(0, cur + v[i]);
}
return vector<int>(n, cur);
}
# | 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... |