#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int search_end(int c1, int c2, int i, ll B, vector<ll> &Front_Sum, vector<ll> &Back_Sum, vector<int> &X, int CASE)
{
int ans = i;
while (c1 <= c2)
{
int m = (c1 + c2) / 2;
switch(CASE)
{
case 1:{
if (Front_Sum[m] - Front_Sum[i] - 1LL * (m - i) * (X[i] - X[0]) > B)
c2 = m - 1;
else
{
ans = m;
c1 = m + 1;
}
break;
}
case 2:{
if (Back_Sum[m] - Back_Sum[i] - 1LL * (i - m) * (X[X.size() - 1] - X[i]) > B)
c1 = m + 1;
else
{
ans = m;
c2 = m - 1;
}
break;
}
}
}
return ans;
}
int cautare_binara(int c1, int c2, int i, ll B, vector<ll> &Back_Sum, vector<int> &X)
{
int ans = i;
while (c1 <= c2)
{
int m = (c1 + c2) / 2;
ll sum2 = Back_Sum[m] - Back_Sum[i] - 1LL * (i - m) * (X[X.size() - 1] - X[i]);
if (sum2 > B)
c1 = m + 1;
else
{
ans = m;
c2 = m - 1;
}
}
return ans;
}
int besthub(int R, int L, int V[], ll B)
{
vector<int> X(R);
vector<int> Best(R);
vector<ll> Front_Sum(R, 0);
vector<ll> Back_Sum(R, 0);
for (int i = 0; i < R; i++)
X[i] = V[i];
for (int i = 1; i < R; i++)
Front_Sum[i] = Front_Sum[i - 1] + X[i] - X[0];
for (int i = R - 2; i >= 0; i--)
Back_Sum [i]= Back_Sum[i + 1] + X[R - 1] - X[i];
for (int i = 0; i < R; i++)
{
int left = search_end(0, i, i, B, Front_Sum, Back_Sum, X, 2);
int right = search_end(i, R - 1, i, B, Front_Sum, Back_Sum, X, 1);
int c1 = i, c2 = right, ans = 1;
while (c1 <= c2)
{
int m = (c1 + c2) / 2;
ll sum = Front_Sum[m] - Front_Sum[i] - 1LL * (m - i) * (X[i] - X[0]);
int part = cautare_binara(left, i, i, B - sum, Back_Sum, X);
ans = max(ans, m - part + 1);
if (part - 1 >= 0 && X[i] - X[part - 1] < X[m] - X[i])
c2 = m - 1;
else
c1 = m + 1;
}
Best[i] = ans;
}
int Max = Best[0];
for (int i = 0; i < R; i++)
Max = max(Max, Best[i]);
return Max;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
356 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
3 ms |
352 KB |
Output is correct |
26 |
Correct |
3 ms |
588 KB |
Output is correct |
27 |
Correct |
3 ms |
360 KB |
Output is correct |
28 |
Correct |
3 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
872 KB |
Output is correct |
2 |
Correct |
7 ms |
1112 KB |
Output is correct |
3 |
Correct |
69 ms |
5016 KB |
Output is correct |
4 |
Correct |
85 ms |
4956 KB |
Output is correct |
5 |
Correct |
15 ms |
4188 KB |
Output is correct |
6 |
Correct |
13 ms |
4044 KB |
Output is correct |
7 |
Correct |
68 ms |
5788 KB |
Output is correct |
8 |
Correct |
74 ms |
5724 KB |
Output is correct |
9 |
Correct |
31 ms |
3940 KB |
Output is correct |
10 |
Correct |
31 ms |
4184 KB |
Output is correct |
11 |
Correct |
66 ms |
6084 KB |
Output is correct |
12 |
Correct |
83 ms |
6080 KB |
Output is correct |
13 |
Correct |
17 ms |
4188 KB |
Output is correct |
14 |
Correct |
17 ms |
4440 KB |
Output is correct |
15 |
Correct |
47 ms |
5212 KB |
Output is correct |
16 |
Correct |
61 ms |
5212 KB |
Output is correct |
17 |
Correct |
58 ms |
5464 KB |
Output is correct |
18 |
Correct |
74 ms |
5468 KB |
Output is correct |
19 |
Correct |
62 ms |
5708 KB |
Output is correct |
20 |
Correct |
78 ms |
5720 KB |
Output is correct |