#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
int len(T &a){
return a.size();
}
const ll infl = 1e8;
#include <vector>
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
int m = len(v);
vector<ll> suf(m + 1), mx(m + 1), mn(m + 1);
mx[m] = 0, mn[m] = 0;
for(int i = m - 1; i >= 0; i --){
suf[i] = suf[i + 1] - v[i];
mx[i] = max(mx[i + 1], suf[i]);
mn[i] = min(mn[i + 1], suf[i]);
}
for(int i = 0; i < n; i ++){
int l = 0, r = m;
while(l <= r){
int mid = (l + r) >> 1;
if(mx[mid] - mn[mid] >= c[i]){
l = mid + 1;
}else r = mid - 1;
}
r ++;
if(r == 0 || v[r - 1] < 0){
c[i] = -mn[r];
}else{
c[i] = c[i] - mx[r];
}
}
//for(auto u : suf) cout << u << ' ';cout << endl;
return c;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
16084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 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 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
56 ms |
12236 KB |
Output is correct |
4 |
Correct |
49 ms |
4036 KB |
Output is correct |
5 |
Correct |
107 ms |
14764 KB |
Output is correct |
6 |
Correct |
113 ms |
15444 KB |
Output is correct |
7 |
Correct |
110 ms |
15960 KB |
Output is correct |
8 |
Correct |
105 ms |
14684 KB |
Output is correct |
9 |
Correct |
119 ms |
16084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |