# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969905 | urieg | Rice Hub (IOI11_ricehub) | C++17 | 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>
#include "ricehub.h"
using namespace std;
typedef long long ll;
// for moondance
int besthub(int R, int L, int X[], long long B){
vector<ll>x(R), p(R);
for(int i=0;i<R;i++){
x[i] = z[i];
p[i] = x[i];
if(i)p[i] += p[i-1];
}
int ans = 0;
ll sum = 0;
int l = 0, r = 0;
for(int i =0;i<R;i++){
l = r = i;
sum = 0;
while(l>0 && r<R-1 && sum <= B){
if(l>0 && r<R-1){
if(x[i]-x[l-1] < x[r+1]-x[i]){
if(sum + x[i]-x[l-1] <= B){
sum += x[i]-x[l-1];
l--;
}
else break;
}
else{
if(sum + x[r+1]-x[i] <= B){
sum += x[r+1]-x[i];
r++;
}
else break;
}
}
else if(l>0){
if(sum + x[i]-x[l-1] <= B){
sum += x[i]-x[l-1];
l--;
}
else break;
}
else if(r<R-1){
if(sum + x[r+1]-x[i] <= B){
sum += x[r+1]-x[i];
r++;
}
else break;
}
}
ans = max(ans, r-l+1);
}
return ans;
}