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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int besthub(int n, int L, int X[], long long B){
vector<ll> pref(n, 0);
for(int i = 0; i < n; i++){
if(i) pref[i] = pref[i-1];
pref[i]+=X[i];
}
auto sum = [&](int l, int r){
return pref[r]-(l?pref[l-1]:0);
};
int ans = 0;
for(int i = 0; i < n; i++){
int c = min(i, n-i-1);
int a = 1, b = c;
while(a < b){
int md = (a+b+1)/2;
if(sum(i+1, i+c)-sum(i-c, i-1) <= B) a = md;
else b = md-1;
}
if(c == 0) a = 0;
if(sum(i+1, i+a)-sum(i-a, i-1) <= B) ans = max(ans, 2*a+1);
if(i+a+1 < n && sum(i+1, i+a+1)-sum(i-a, i-1)-X[i] <= B) ans = max(ans, 2*a+2);
}
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... |