#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
const int N = 1e5+7;
vector <ll> pref(N), suff(N), v(N);
int n;
ll getpref(int l, int r){
return pref[r]-11l*(l-1)*(v[r]-v[l-1])-pref[l-1];
}
ll getsuff(int l, int r){
return suff[l]-1ll*(n-r-1)*(v[r+1]-v[l])-suff[r+1];
}
bool check(int l, int r, ll B){
int flag = 0, x = r-l+1;
for(int i = 1; i+x-1 <= n; i++){
int mid = (i+i+x-1) >> 1;
if(getpref(i, mid)+getsuff(mid, i+x-1) <= B){
flag++;
break;
}
}
return flag;
}
int besthub(int R, int L, int X[], long long B){
n = R;
int i;
for(i = 0; i < R; i++){
v[i+1] = X[i];
}
for(i = 1; i <= n; i++){
pref[i] = pref[i-1]+1ll*(i-1)*(v[i]-v[i-1]);
}
for(i = n; i; i--){
suff[i] = suff[i+1]+1ll*(n-i)*(v[i+1]-v[i]);
}
int l = 1, r = n;
while(l < r){
int mid = (l+r) >> 1;
if(check(l, r, B)) l = mid+1;
else r = mid;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |