#include "candies.h"
#include <algorithm>
#include <cstdio>
const int N = 200005;
int n, a[N], c[N];
long long inc[N];
std::vector<int> distribute_candies(std::vector<int> c_, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
n = (int)c_.size();
std::vector<int> ans(n);
if (n <= 2000 && l.size() <= 2000) {
for (int i = 0; i < n; ++i) c[i] = c_[i];
for (int i = 0; i < (int)l.size(); ++i) {
int ll = l[i], rr = r[i] + 1, d = v[i];
for (int j = ll; j < rr; ++j) a[j] += d;
if (d > 0) {
for (int j = ll; j < rr; ++j) a[j] = a[j] < c[j] ? a[j] : c[j];
} else {
for (int j = ll; j < rr; ++j) a[j] = a[j] < 0 ? 0 : a[j];
}
}
for (int i = 0; i < n; ++i) ans[i] = a[i];
} else {
bool pos = 1;
for (int i = 0; i < (int)v.size(); ++i) if (v[i] < 0) pos = 0;
if (pos) {
for (int i = 0; i < (int)l.size(); ++i) {
inc[l[i]] += v[i];
inc[r[i] + 1] -= v[i];
}
for (int i = 0; i < n; ++i) {
if (i) inc[i] += inc[i - 1];
ans[i] = std::min((long long)c[i], inc[i]);
}
} else {
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
107 ms |
13736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
53 ms |
8008 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
55 ms |
7620 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
424 KB |
Output is correct |
6 |
Incorrect |
107 ms |
13736 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |