# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491284 | niloyroot | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
ll besthub(ll r, ll l, ll x[], ll b){
ll ans=0,n,m,cnt,temp;
forp(i,0,r-1){
n=i-1,m=i+1;
cnt=1,temp=0;
while(temp<=b){
if(n<0 && m>r-1){
break;
} else if(n>=0 && m>r-1){
if(temp+(x[i]-x[n])<=b){
temp+=(x[i]-x[n]);
n--;
cnt++;
} else {
break;
}
} else if(m<=r-1 && n<0){
if(temp+(x[m]-x[i])<=b){
temp+=(x[m]-x[i]);
m++;
cnt++;
} else {
break;
}
} else {
if(x[m]-x[i]<x[i]-x[n] && temp+(x[m]-x[i])<=b){
temp+=(x[m]-x[i]);
m++;
cnt++;
} else if(temp+(x[i]-x[n])<=b){
temp+=(x[i]-x[n]);
n--;
cnt++;
} else {
break;
}
}
}
ans=max(ans,cnt);
}
return ans;
}