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