#include<bits/stdc++.h>
#include"candies.h"
using namespace std;
using ll = long long;
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
int m = (int)v.size();
auto vcur = vector<int>(v.size(), 0);
vector<vector<int>> in(n), out(n);
for (int i = 0; i < m; i++) {
in[l[i]].push_back(i);
out[r[i]].push_back(i);
}
for(int i = 0; i < n; i ++){
for (int j : in[i]) {
vcur[j] = v[j];
}
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]);
}
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 (int j : out[i]) {
vcur[j] = 0;
}
}
//for(auto u : suf) cout << u << ' ';cout << endl;
return c;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5038 ms |
29464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3349 ms |
13056 KB |
Output is correct |
4 |
Correct |
1596 ms |
11824 KB |
Output is correct |
5 |
Execution timed out |
5044 ms |
23868 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |