#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size(), q = l.size();
if (n <= 2000 && q <= 2000) {
vector<int> a(n, 0);
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
a[j] += v[i];
a[j] = min(a[j], c[j]);
a[j] = max(a[j], 0);
}
}
return a;
}
bool allpos = true;
for (int &x : v) {
allpos &= (x > 0);
}
if (allpos) {
ll int diff[n] = {0};
for (int i = 0; i < q; i++) {
diff[l[i]] += v[i];
if (r[i] != n - 1) diff[r[i] + 1] -= v[i];
}
vector<int> ans;
ll int ps = 0;
for (int i = 0; i < n; i++) {
ps += diff[i];
ans.pb((ps < c[i] ? ps : c[i]));
}
return ans;
}
return {};
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
14024 KB |
Output is correct |
2 |
Correct |
101 ms |
13348 KB |
Output is correct |
3 |
Correct |
117 ms |
13088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
51 ms |
8012 KB |
Output isn't correct |
3 |
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 |
Incorrect |
47 ms |
4972 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
105 ms |
14024 KB |
Output is correct |
7 |
Correct |
101 ms |
13348 KB |
Output is correct |
8 |
Correct |
117 ms |
13088 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
51 ms |
8012 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |