#include "candies.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n=c.size(), m=l.size();
vi ch(m);
vvi addOp(n), remOp(n);
forR(i, m) {
addOp[l[i]].push_back(i);
if(r[i] + 1 < n) remOp[r[i]+1].push_back(i);
}
vi ret(n);
forR(i, n) {
for(int j : addOp[i]) ch[j] = v[j];
for(int j : remOp[i]) ch[j] = 0;
int besInd=n, uc=0, dc=0;
for(int j = n-1; j >= 0; --j) {
uc = max(uc + ch[j], 0);
dc = min(dc + ch[j], c[i]);
if(uc >= c[i] || dc <= -c[i]) break;
else besInd = j;
}
// cerr << i << ": \n";
// for(int j : ch) cerr << j << ' ';
// cerr << '\n';
// cerr << besInd << ' ' << uc << ' ' << dc << '\n';
if(uc >= c[i]) {
int lasPos = besInd - 1;
for(int j = besInd; j < n && ch[j] >= 0; ++j){
lasPos = j;
}
int st = lasPos + 1, cur = c[i];
REP(j, st, n) cur = min(c[i], cur + ch[j]);
ret[i] = cur;
} else {
int lasNeg = besInd;
for(int j = besInd; j < n && ch[j] <= 0; ++j) {
lasNeg = j;
}
int st = lasNeg + 1, cur = 0;
REP(j, st, n) cur = max(0, cur + ch[j]);
ret[i] = cur;
}
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1478 ms |
25076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |