#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
ll pre[100005];
int besthub(int n, int m, int a[], long long c){
for(int i = 1; i <= n; i++){
pre[i] = pre[i - 1] + a[i - 1];
}
ll l = 1, r = n, res = 0;
while(l <= r){
ll mid = (l + r) / 2, f = 0;
for(ll i = 1; i <= n; i++){
if(i + mid - 1 > n) break;
ll midd = (i + i + mid - 1) / 2;
ll cost = -(pre[midd] - pre[i - 1]) + a[midd] * (midd - i + 1) + (pre[i + mid - 1] - pre[midd]) - (i + mid - 1 - midd) * a[midd];
if(cost <= c){
f = 1;
}
}
if(f){
res = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2488 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2488 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2492 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2400 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2504 KB |
Output is correct |
21 |
Correct |
1 ms |
2596 KB |
Output is correct |
22 |
Correct |
1 ms |
2512 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2976 KB |
Output is correct |
3 |
Correct |
10 ms |
3676 KB |
Output is correct |
4 |
Correct |
10 ms |
3632 KB |
Output is correct |
5 |
Correct |
6 ms |
2908 KB |
Output is correct |
6 |
Correct |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
8 ms |
3420 KB |
Output is correct |
8 |
Correct |
9 ms |
3416 KB |
Output is correct |
9 |
Correct |
5 ms |
2724 KB |
Output is correct |
10 |
Correct |
5 ms |
2908 KB |
Output is correct |
11 |
Correct |
10 ms |
3500 KB |
Output is correct |
12 |
Correct |
10 ms |
3676 KB |
Output is correct |
13 |
Correct |
6 ms |
2860 KB |
Output is correct |
14 |
Correct |
6 ms |
2904 KB |
Output is correct |
15 |
Correct |
7 ms |
3264 KB |
Output is correct |
16 |
Correct |
7 ms |
3420 KB |
Output is correct |
17 |
Correct |
9 ms |
3500 KB |
Output is correct |
18 |
Correct |
8 ms |
3500 KB |
Output is correct |
19 |
Correct |
9 ms |
3924 KB |
Output is correct |
20 |
Correct |
9 ms |
3676 KB |
Output is correct |