#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];
for(int i =0 ; i < q ; i ++){
prefix[l[i]]+=v[i];
prefix[r[i]+1]-= v[i];
}
int cuenta =0 ;
for(int i = 0 ; i <n ; i ++){
cuenta+=prefix[i];
s[i] = min(cuenta, 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
106 ms |
13856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
52 ms |
9124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
62 ms |
9172 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Incorrect |
106 ms |
13856 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |