# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333635 | blue | Rice Hub (IOI11_ricehub) | C++17 | 20 ms | 2284 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 <vector>
using namespace std;
int besthub(int R, int L, int X[], long long B) //fields, max coordinate, i'th field, budget
{
int fields = R;
vector<long long> F(R+2);
F[0] = -(2e16 + 1);
F[R+1] = (4e16 + 1);
for(int i = 1; i <= R; i++) F[i] = X[i-1];
int l = 1; //leftmost field
int m = 1; //hub
int r = 1; //rightmost field
long long c = 0; //current cost
int res = 1; //running result
while(1)
{
if(F[r+1] - F[m] + c <= B)
{
c += F[r+1] - F[m];
r++;
}
else if(F[m] - F[l] > F[r+1] - F[m])
{
c -= (F[m] - F[l]);
l++;
}
else if(m < R)
{//l * * m m1 * r
/*if(F[m+1] - F[m] > B)
{
l = m = r = m+1;
c = 0;
continue;
}*///IMPORTANT
c += (F[m+1] - F[m]) * ((m - (l - 1)) - (r - m));
m++;
while(c > B)
{
c -= F[m] - F[l];
l++;
}
}
else break;
res = max(res, r - l + 1);
}
return res;
}
Compilation message (stderr)
# | 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... |