120792024-11-30 12:19:05DávidPontos átlag 2cpp17Accepted 100/100126ms3528 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

bool f(ll x, ll k, vector<ll> arak) {
	ll cel = arak.size() * k;
	for(int i = 0; i < arak.size(); i++) {
		cel -= arak[i];
	}
	for(int i = 0; i < arak.size(); i++) {
		if(cel > 0) cel -= min(cel, x);
		else if(cel < 0) cel += min(abs(cel), min(arak[i] - 1, x));
	}
	return cel == 0;
}

int main() {
	ll n, k;
	cin >> n >> k;

	vector<ll> arak(n);

	for(int i = 0; i < n; i++) {
		cin >> arak[i];
	}

	ll l = -1, r = 1e15;
	while(l < r - 1) {
		ll kozep = (l + r) / 2;
		if(f(kozep, k, arak)) {
			r = kozep;
		} else {
			l = kozep;
		}
	}

	cout << r << endl;
	
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms500 KiB
subtask210/10
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted1ms320 KiB
7Accepted1ms512 KiB
8Accepted1ms324 KiB
subtask320/20
9Accepted64ms3384 KiB
10Accepted65ms3384 KiB
11Accepted63ms3228 KiB
12Accepted64ms3228 KiB
13Accepted65ms3384 KiB
14Accepted65ms3384 KiB
15Accepted68ms3384 KiB
16Accepted74ms3512 KiB
17Accepted1ms320 KiB
subtask424/24
18Accepted1ms320 KiB
19Accepted1ms320 KiB
20Accepted1ms320 KiB
21Accepted1ms320 KiB
22Accepted2ms388 KiB
23Accepted1ms320 KiB
24Accepted1ms320 KiB
25Accepted1ms320 KiB
26Accepted1ms320 KiB
27Accepted1ms396 KiB
28Accepted1ms320 KiB
subtask546/46
29Accepted68ms3516 KiB
30Accepted89ms3512 KiB
31Accepted61ms2040 KiB
32Accepted82ms2988 KiB
33Accepted111ms3384 KiB
34Accepted119ms3488 KiB
35Accepted116ms3508 KiB
36Accepted126ms3528 KiB
37Accepted126ms3504 KiB
38Accepted107ms3300 KiB
39Accepted43ms1480 KiB
40Accepted3ms436 KiB
41Accepted1ms320 KiB