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;
int besthub(int n, int l, int x[], long long money)
{
int a = 0;
int b = 0;
ll cost = 0;
int best = 0;
while (b + 1 < n && cost + x[(b + 1)] - x[0] <= money)
{
cost += x[(b + 1)] - x[0];
b++;
}
int left = 0;
int right = b;
best = max(best, b - a + 1);
//cout << "oj " << cost << endl;
for (int i = 1; i < n; i++)
{
cost -= (ll) right * (x[i] - x[i - 1]);
left++;
cost += (ll) left * (x[i] - x[i - 1]);
right--;
while(cost > money)
{
cost -= x[i] - x[a];
a++;
left--;
}
while(b + 1 < n && x[b + 1] - x[i] + cost < money)
{
cost += x[b + 1] - x[i];
b++;
right++;
}
while (b + 1 < n && x[i] - x[a] > x[b + 1] - x[i])
{
cost -= x[i] - x[a];
a++;
left--;
cost += x[b + 1] - x[i];
b++;
right++;
}
//cout << "oj " << a << " " << b << " " << cost << endl;
best = max(best, b - a + 1);
}
return best;
}
# | 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... |