120782024-11-30 12:17:14DávidPontos átlag 2cpp17Wrong answer 0/100114ms3536 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 = 0, r = 1e10;
	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
2Accepted1ms320 KiB
subtask20/10
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted1ms320 KiB
7Wrong answer1ms320 KiB
8Accepted1ms320 KiB
subtask30/20
9Accepted54ms3516 KiB
10Accepted56ms3520 KiB
11Wrong answer52ms3404 KiB
12Accepted52ms3384 KiB
13Accepted54ms3384 KiB
14Accepted54ms3528 KiB
15Accepted57ms3388 KiB
16Accepted61ms3380 KiB
17Accepted1ms320 KiB
subtask40/24
18Accepted2ms324 KiB
19Accepted1ms320 KiB
20Accepted1ms320 KiB
21Accepted1ms500 KiB
22Accepted1ms508 KiB
23Accepted1ms320 KiB
24Accepted1ms320 KiB
25Wrong answer1ms508 KiB
26Accepted1ms320 KiB
27Accepted1ms320 KiB
28Accepted1ms320 KiB
subtask50/46
29Accepted57ms3536 KiB
30Accepted78ms3520 KiB
31Accepted54ms2040 KiB
32Accepted75ms2988 KiB
33Accepted100ms3504 KiB
34Accepted108ms3384 KiB
35Wrong answer108ms3504 KiB
36Accepted114ms3512 KiB
37Accepted114ms3384 KiB
38Accepted98ms3384 KiB
39Accepted39ms1480 KiB
40Accepted3ms320 KiB
41Accepted1ms508 KiB