#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, Q;
vector<int> a;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
N = c.size(), Q = l.size();
a.resize(N);
if(N <= 2000 && Q <= 2000){
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;
} else {
vector<ll> s(N + 1);
for(int i = 0; i < Q; i++){
s[l[i]] += v[i];
s[r[i] + 1] -= v[i];
}
for(int i = 1; i < N; i++){
s[i] += s[i - 1];
}
for(int i = 0; i < N; i++){
a[i] = min((int)s[i], c[i]);
}
return a;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
99 ms |
9660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
56 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
50 ms |
4964 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
340 KB |
Output is correct |
6 |
Incorrect |
99 ms |
9660 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |