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_rice = 0;
for (int i = 0; i < R; i++) {
int c = X[i];
int l = i, r = i + 1;
int q = B;
int t = 0;
if (l >= 0 && r <= R - 1) {
int l_cost = abs(c - X[l]);
int r_cost = abs(c - X[r]);
if (min(l_cost, r_cost) > q) {
max_rice = max(t, max_rice);
continue;
}
if (l_cost <= r_cost) {
t++;
l--;
q -= l_cost;
} else {
t++;
r++;
q -= r_cost;
}
} else if (r <= R - 1) {
// can't go left
int r_cost = abs(c - X[r]);
if (r_cost > q) {
max_rice = max(t, max_rice);
continue;
}
t++;
r++;
q -= r_cost;
} else if (l >= 0) {
int l_cost = abs(c - X[l]);
if (l_cost > q) {
max_rice = max(t, max_rice);
continue;
}
t++;
l--;
q -= l_cost;
} else {
max_rice = max(t, max_rice);
continue;
}
}
return max_rice;
}
# | 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... |