제출 #511338

#제출 시각아이디문제언어결과실행 시간메모리
511338AdamGSRice Hub (IOI11_ricehub)C++14
100 / 100
21 ms2656 KiB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
ll sum[LIM], T[LIM];
ll Q(int l, int r) {
	return sum[r]-(l?sum[l-1]:0);
}
int besthub(int n, int m, int P[], long long b) {
	rep(i, n) {
		if(i) sum[i]=sum[i-1];
		T[i]=P[i];
		sum[i]+=T[i];
	}
	ll ans=1;
	rep(i, n) {
		ll p=0, k=min(i, n-i-1);
		while(p<k) {
			ll sr=(p+k+1)/2;
			if(Q(i+1, i+sr)-Q(i-sr, i-1)<=b) p=sr; else k=sr-1;
		}
		ans=max(ans, 2*p+1);
	}
	for(int i=1; i<n; ++i) {
		ll p=0, k=min(i-1, n-i-1);
		while(p<k) {
			ll sr=(p+k+1)/2;
			if(Q(i+1, i+sr)-Q(i-sr-1, i-1)+T[i]<=b) p=sr; else k=sr-1;
		}
		if(T[i]-T[i-1]<=b) ans=max(ans, 2*p+2);
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...