This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#ifdef dremix
#define p(x) cerr<<#x<<" = "<<x<<endl;
#define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
#define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl;
#define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl;
#define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl;
#else
#define p(x)
#define p2(x,y)
#define pp(x)
#define pv(x)
#define ppv(x)
#endif
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int maxp = 22;
const ld EPS = 1e-18;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5+1;
int n,arr[N];
ll m;
bool chk(int x){
int i;
int idx = x/2;
ll pos = arr[idx++];
ll curr = 0;
for(i=0;i<x;i++)
curr += abs(arr[i]-pos);
if(curr<=m)return 1;
for(i=x;i<n;i++){
curr -= abs(arr[i-x]-pos);
curr += abs(arr[i]-pos);
ll left = x/2;
ll right = (x+1)/2;
ll nxt = arr[idx++];
ll diff = nxt-pos;
curr += diff*left;
curr -= diff*right;
pos = nxt;
if(curr<=m)return 1;
}
return 0;
}
int besthub(int R, int L, int X[], long long B){
n = R;
m = B;
int i;
for(i=0;i<n;i++)arr[i] = X[i];
int l=1,r=n;
int ans = 0;
while(l<=r){
int mid = (l+r)/2;
bool ok = chk(mid);
if(ok){
l = mid+1;
ans = mid;
}
else
r = mid-1;
}
return ans;
}
# | 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... |