Submission #753716

#TimeUsernameProblemLanguageResultExecution timeMemory
753716nicksmsRice Hub (IOI11_ricehub)C++17
100 / 100
17 ms3324 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using db=long double;
template<class T> using V=vector<T>;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int,int>;
#define f first
#define s second
#define sz(x) (int)((x).size())

int besthub(int R, int L, int X[], ll B) {
	vl pre(R+1);
	vl x(R);
	for (int i = 0; i < R; i++) pre[i+1] = pre[i] + (x[i]=X[i]);
	int best = 1;
	int l = 0, r = 1;
	while (l < R) {
		r = max(l+1, r);
		while (r <= R) {
			int m = (l+r)/2;
			ll lo = pre[m]-pre[l];
			ll up = pre[r]-pre[m];
			lo = x[m]*(m-l) - lo;
			up -= x[m]*(r-m);
			if (lo + up <= B) {
				best = max(best, r-l);
				r += 1;
			} else break;
		}
		l++;
	}
	return best;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...