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;
#define ll long long
int besthub(int r, int l, int x[], long long b) {
int ans = 0;
int left = 0, right = 0, middle = 0;
ll leftsum = 0, rightsum = 0;
bool prev = true;
while (right != r - 1) {
if (prev) {
if ((right - left + 1) % 2 == 0) {
right++; middle++;
leftsum += (ll)(middle - left) * (x[middle] - x[middle - 1]);
rightsum -= (ll)(right - middle) * (x[middle] - x[middle - 1]);
rightsum += x[right] - x[middle];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
} else {
right++;
rightsum += x[right] - x[middle];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
}
} else {
if ((right - left + 1) % 2 == 0) {
left++; middle++;
leftsum += (ll)(middle - left + 1) * (x[middle] - x[middle - 1]);
rightsum -= (ll)(right - middle + 1) * (x[middle] - x[middle - 1]);
leftsum -= x[middle] - x[left - 1];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
} else {
left++;
leftsum -= x[middle] - x[left - 1];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
}
}
//cout << left << ' ' << middle << ' ' << right << ' ' << leftsum << ' ' << rightsum << '\n';
}
return ans;
}
# | 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... |