#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]-1ll*(l-1)*(v[r]-v[l-1])-pref[l-1];
}
ll getsuff(int l, int r){
return suff[l]-1ll*(n-r)*(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |