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 endl '\n'
#define ll long long
#define pll pair<ll, ll>
int besthub(int n, int l, int a[], long long b)
{
// 0 1 2 3 4 5
ll mid = a[n/2];
if (n%2==0){
mid += a[n/2+1];
mid /= 2;
}
ll sum = 0, ind = -1, mx = 0;
for (ll i = n/2+1; i<n; i++){
sum += a[i];
if (sum - (i-n/2)*mid <= b){
ind = i;
mx++;
}
else {
sum -= a[i];
break;
}
}
// 24 4 2 10
b -= (sum - (ind-n/2)*mid);
ll sum2 = 0;
for (ll i = n/2; i>=0; i--){
sum2 += a[i];
if ((n/2-i+1)*mid - sum2 <= b){
mx = max(mx, ind-i+1);
}
else {
b += (a[ind] - mid);
ind--;
}
}
return mx;
}
# | 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... |