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 = 1;
for(int i = 0; i < n; i++){
int c = min(i, n-i-1);
int a = 1, b = c;
if(c == 0){
if(i+1 < n && X[i+1]-X[i] <= B) ans = max(ans, 2);
continue;
}
while(a < b){
int md = (a+b+1)/2;
if(sum(i+1, i+md)-sum(i-md, i-1) <= B) a = md;
else b = md-1;
}
if(sum(i+1, i+a)-sum(i-a, i-1) <= B) ans = max(ans, 2*a+1);
else a = 0;
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... |