#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e5 + 5, mxq = 1e6 + 5, sq = 400;
const int base = (1 << 18);
const int inf = 1e9, neg = -69420;
#include "ricehub.h"
ll a[mxn + 1], pref[mxn + 1], b, n;
bool ck(int mid){
for(int i = 1; i + mid - 1 <= n; i++){
int id = i + (mid) / 2;
ll cand = a[id] * (id - i + 1) - (pref[id] - pref[i - 1]) + (pref[i + mid - 1] - pref[id - 1]) - (a[id] * (i + mid - 1 - id + 1));
if(cand <= b)return(1);
}
return(0);
}
int besthub(int R, int L, int X[], long long B)
{
b = B; n = R;
for(int i = 0; i < R; i++)a[i + 1] = X[i];
for(int i = 1; i <= R; i++){
pref[i] = pref[i - 1] + a[i];
}
int l = 1, r = R, ans = 0;
while(l <= r){
int mid = (l + r) >> 1;
if(ck(mid)){
ans = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
return(ans);
}
/*
#define MAX_R 1000000
static int R, L;
static long long B;
static int X[MAX_R];
static int solution;
inline
void my_assert(int e) {if (!e) abort();}
static void read_input()
{
int i;
my_assert(3==scanf("%d %d %lld",&R,&L,&B));
for(i=0; i<R; i++)
my_assert(1==scanf("%d",&X[i]));
my_assert(1==scanf("%d",&solution));
}
int main()
{
int ans;
read_input();
ans = besthub(R,L,X,B);
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d instead of %d.\n",ans,solution);
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
628 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
10 ms |
3280 KB |
Output is correct |
4 |
Correct |
14 ms |
3284 KB |
Output is correct |
5 |
Correct |
5 ms |
1620 KB |
Output is correct |
6 |
Correct |
6 ms |
1620 KB |
Output is correct |
7 |
Correct |
9 ms |
3032 KB |
Output is correct |
8 |
Correct |
9 ms |
3028 KB |
Output is correct |
9 |
Correct |
5 ms |
1492 KB |
Output is correct |
10 |
Correct |
5 ms |
1496 KB |
Output is correct |
11 |
Correct |
10 ms |
3236 KB |
Output is correct |
12 |
Correct |
10 ms |
3340 KB |
Output is correct |
13 |
Correct |
7 ms |
1620 KB |
Output is correct |
14 |
Correct |
5 ms |
1620 KB |
Output is correct |
15 |
Correct |
8 ms |
2516 KB |
Output is correct |
16 |
Correct |
8 ms |
2528 KB |
Output is correct |
17 |
Correct |
9 ms |
3008 KB |
Output is correct |
18 |
Correct |
12 ms |
2912 KB |
Output is correct |
19 |
Correct |
14 ms |
3156 KB |
Output is correct |
20 |
Correct |
10 ms |
3156 KB |
Output is correct |