This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define MAXN 100000
ll a[MAXN];
ll b[MAXN];
bool check(ll n,ll l,ll r,vector<ll>& v,ll x){
if(l==r) return 1;
int mid=(l+r)/2;
ll o=a[mid]+b[mid];
o-=a[l]+(v[mid]-v[l])*l;
o-=b[r]+(v[r]-v[mid])*(n-r-1);
if(o>x) return 0;
return 1;
}
int besthub(int n,int m,int X[],ll x){
ll o,p,q;
vector<ll> v;
for(int i=0;i<n;i++)
v.append(X[i]);
a[0]=b[n-1]=o=p=q=0;
for(int i=1;i<n;i++)
a[i]=a[i-1]+i*(v[i]-v[i-1]);
for(int i=n-2;i>=0;i--)
b[i]=b[i+1]+(n-1-i)*(v[i+1]-v[i]);
while(q<=n){
if(check(n,p,q,v,x)){
o=max(o,q-p);
q++;
}
else p++;
}
return o;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |