#include "candies.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
int n, q;
vector<int>s;
void initialize(){
for (int i = 0; i < n; i++){
s.pb(0);
}
}
void case1(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
for(int i = 0 ; i < q ; i ++){
for(int j = l[i] ; j <= r[i] ; j ++){
if(v[i] > 0){
s[j] = min(c[j], v[i]+s[j]);
//cout << "s[" << j << "] = " << s[j] << endl;
}else{
s[j] = max(0, s[j]+v[i] );
// << "s[" << j << "] = " << s[j] << endl;
}
}
}
}
void case2(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
ll prefix[n+2];
memset(prefix, 0, sizeof prefix) ;
for(int i =0 ; i < q ; i ++){
prefix[l[i]]+=v[i];
prefix[r[i]+1]-= v[i];
}
ll cuenta =0 ;
for(int i = 0 ; i <n ; i ++){
cuenta+=prefix[i];
//cuenta = min((ll)1000000000, cuenta);
//cout << "cuenta = " << cuenta << endl;
s[i] = min(cuenta, (ll)c[i]);
}
}
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();
initialize();
if(n<=2000 and q <= 2000){
case1(c, l, r, v);
}
else{
case2(c, l, r, v);
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
12660 KB |
Output is correct |
2 |
Correct |
97 ms |
16292 KB |
Output is correct |
3 |
Correct |
110 ms |
16084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
53 ms |
7904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
54 ms |
7916 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 |
340 KB |
Output is correct |
6 |
Correct |
103 ms |
12660 KB |
Output is correct |
7 |
Correct |
97 ms |
16292 KB |
Output is correct |
8 |
Correct |
110 ms |
16084 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
53 ms |
7904 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |