#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int pos[N];
ll sum[N];
int n;
long long money;
bool poss(int len)
{
ll cost = 0;
int a = 0;
int b = len - 1;
int mid = (a + b) / 2;
//cout << len << " " << cost << " " << money << endl;
while (b < n)
{
cost = 0;
if (a != mid) cost -= sum[mid - 1];
if (a != 0) cost += sum[a - 1];
cost += sum[b];
cost -= (ll) (b - mid) * pos[mid];
cost += (ll) (mid - a) * (pos[mid]);
cost -= sum[mid];
mid++;
a++;
b++;
if (cost <= money) return true;
}
return false;
}
int binarySearch()
{
int a = 1;
int b = n;
int res = -1;
while (a <= b)
{
int mid = (a + b) / 2;
if (poss(mid))
{
res = mid;
a = mid + 1;
} else
{
b = mid - 1;
}
}
return res;
}
int besthub(int n1, int l, int x[], long long money1)
{
money = money1;
n = n1;
for (int i = 0; i < n; i++)
{
pos[i] = x[i];
}
for (int i = 0; i < n; i++)
{
sum[i] += pos[i];
if (i != 0) sum[i] += sum[i - 1];
}
return binarySearch();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Correct |
16 ms |
1900 KB |
Output is correct |
4 |
Correct |
16 ms |
1900 KB |
Output is correct |
5 |
Correct |
8 ms |
1132 KB |
Output is correct |
6 |
Correct |
9 ms |
1644 KB |
Output is correct |
7 |
Correct |
15 ms |
2668 KB |
Output is correct |
8 |
Correct |
15 ms |
2668 KB |
Output is correct |
9 |
Correct |
8 ms |
1388 KB |
Output is correct |
10 |
Correct |
8 ms |
1388 KB |
Output is correct |
11 |
Correct |
17 ms |
2924 KB |
Output is correct |
12 |
Correct |
17 ms |
2924 KB |
Output is correct |
13 |
Correct |
9 ms |
1516 KB |
Output is correct |
14 |
Correct |
10 ms |
1644 KB |
Output is correct |
15 |
Correct |
13 ms |
2284 KB |
Output is correct |
16 |
Correct |
13 ms |
2284 KB |
Output is correct |
17 |
Correct |
15 ms |
2796 KB |
Output is correct |
18 |
Correct |
15 ms |
2668 KB |
Output is correct |
19 |
Correct |
16 ms |
2796 KB |
Output is correct |
20 |
Correct |
16 ms |
2796 KB |
Output is correct |