제출 #1216887

#제출 시각아이디문제언어결과실행 시간메모리
1216887giorgi123glm쌀 창고 (IOI11_ricehub)C++20
100 / 100
15 ms2376 KiB
#include "ricehub.h"
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int besthub(int R, int L, int X[], long long B) {
	vector <long long> v (R + 1);
	for (int i = 1; i <= R; i++)
		v[i] = X[i - 1];
	vector <long long> pref (R + 1);
	for (int i = 1; i <= R; i++)
		pref[i] = pref[i - 1] + v[i];

	long long ans = 0;
	for (int i = 1; i <= R; i++) {
		// chooce rice hub
		
		int l = 0, r = R;
		while (l <= r) {
			int mid = (l + r) / 2;
			long long x = mid / 2;
			long long y = mid - x;

			if (i > (R + 1) / 2)
				swap (x, y);

			if (i - x - 1 < 0 || i + y > R) {
				r = mid - 1;
				continue;
			}

			long long prc = (
				x * v[i] - (pref[i - 1] - pref[i - x - 1]) +
				(pref[i + y] - pref[i]) - y * v[i]
			);
			if (prc <= B) {
				ans = max (ans, x + y + 1);
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
	}

	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...