Submission #418257

#TimeUsernameProblemLanguageResultExecution timeMemory
418257AzimjonRice Hub (IOI11_ricehub)C++17
68 / 100
1084 ms1740 KiB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B) {
	auto cost = [&](int x, int y) { return abs(X[x] - X[y]); };

	int ans = -1;

	for (int i = 0; i < R; i++) {
		int cans = 0;
		long long cb = B;

		int l, r;
		l = i;
		r = i + 1;

		while (1) {
			int t;
			if (l == -1 && r != R)
				t = r++;
			else if (r == R && l != -1)
				t = l--;
			else if (cost(i, l) < cost(i, r))
				t = l--;
			else
				t = r++;

			if (cb - cost(i, t) >= 0) {
				cb -= cost(i, t);
				cans++;
			} else {
				break;
			}

			if (l == -1 && r == R)
				break;
		}

		ans = max(cans, ans);
	}

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