#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAXQ = 1000005;
const ll INF = (ll)(1e18);
vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> v)
{
int n = c.size(); int q = v.size();
vector<ll> p;
p.push_back(INF); p.push_back(0LL);
for(int i=0;i<q;i++) p.push_back(p.back() + v[i]);
q+=2;
vector<ll> smax(q),smin(q);
smax[q-1] = smin[q-1] = p[q-1];
for(int i=q-2;i>=0;i--)
{
smax[i] = max(smax[i+1],p[i]);
smin[i] = min(smin[i+1],p[i]);
}
vector<int> final_A(n);
for(int i=0;i<n;i++)
{
int l = 0; int r = q-1;
int ret = -1;
while(l<=r)
{
int mid = (l+r)/2;
if(smax[mid]-smin[mid]>=c[i])
{
ret = mid;
l = mid+1;
}
else r = mid-1;
}
if(p[ret]==smax[ret]) final_A[i] = p[q-1]-smin[ret];
else final_A[i] = c[i]-(smax[ret]-p[q-1]);
}
return final_A;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
146 ms |
13504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
64 ms |
12352 KB |
Output is correct |
4 |
Correct |
73 ms |
4020 KB |
Output is correct |
5 |
Correct |
127 ms |
15544 KB |
Output is correct |
6 |
Correct |
128 ms |
16180 KB |
Output is correct |
7 |
Correct |
131 ms |
16784 KB |
Output is correct |
8 |
Correct |
138 ms |
15460 KB |
Output is correct |
9 |
Correct |
127 ms |
16828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |