#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define mxn 100005
#define mxm 105
#define f first
#define s second
#define pb push_back
#define es " "
#define endl '\n'
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<string, string> pii;
typedef pair<int, pii> pip;
int resp;
ll prefix[mxn], v[mxn];
ll testa(int i, int j){
int med=(i+j)/2;
ll sum=((prefix[j]-prefix[med])-v[med]*(j-med))+((med-i)*v[med]-(prefix[med-1]-prefix[i-1]));
return sum;
}
int besthub(int n, int l, int x[], ll b){
vector<int64_t>pref(n + 1,0),dpref(n + 1,0);
for (int i = 0 ;i<n - 1;++i){
pref[i + 1] = pref[i] + (x[i + 1] - x[i]);
dpref[i + 2] = pref[i + 1] + dpref[i + 1];
}
auto dist = [&](int l,int r){
return pref[r] * (r - l) - dpref[r] + dpref[l];
};
auto distt = [&](int l,int r){
int mid = (l + r)>>1;
return dist(l,mid) + dist(mid,r);
};
for(int i=1; i<=n; i++){
v[i]=x[i-1];
prefix[i]=prefix[i-1]+v[i];
}
for(int i=1; i<=n; i++){
int ini=i, fim=n, meio;
while(ini<=fim){
meio=(ini+fim)/2;
//cout<<i<< " "<<meio<<" "<<distt(i - 1,meio - 1)<<'\n';
if(distt(i - 1, meio - 1)<=b){
resp=max(resp, meio-i+1);
ini=meio+1;
}else{
fim=meio-1;
}
}
}
return resp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
19 ms |
3796 KB |
Output is correct |
4 |
Correct |
18 ms |
3836 KB |
Output is correct |
5 |
Incorrect |
8 ms |
2028 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |