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;
int besthub(int r, int l, int x[], long long b) {
long long left = 0, right = 0, ans = 0;
long long curCost = 0;
while(left < r) {
if(right >= r)
break;
long long OptimalField = (left + right) / 2;
//cout << left << " " << right << " " << OptimalField << " " << curCost << endl;
if(curCost + x[right] - x[OptimalField] <= b) {
curCost += x[right] - x[OptimalField];
ans = max(ans, right - left + 1);
right++;
}
else {
curCost -= x[OptimalField] - x[left++];
}
}
return ans;
}
/*
int main() {
//cout << "Input the number of rice fields" << endl;
int r;
cin >> r;
//cout << "Input the maaimum coordinate" << endl;
int l;
cin >> l;
//cout << "Input r numbers, denoting the rice fields" << endl;
int a[r];
for(int i = 0; i < r; i++) {
cin >> a[i];
}
//cout << "Input the budget" << endl;
int b;
cin >> b;
cout << besthub(r, l, a, b) << endl;
}
*/
# | 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... |