# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
460477 | fuad27 | 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 "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int r, int l, int x[], long long b) {
int MAX = 0;
for(int i = 1;i<r;i++) {
int c = 0;
long long cost = 0;
int p1 = 0, p2 = MAX-1
while(p1 < r and p2 <= r) {
if(cost <= b) {
c = max(p2 - p1, c);
p2++;
if(p2 <= r)
cost+=abs(x[p2-1] - x[i]);
}
else {
cost-=abs(x[p1]-x[i]);
p1++;
}
}
MAX = max(c, MAX);
}
return MAX;
}