69202023-12-19 18:45:30111Pontos átlag 2cpp17Accepted 100/10078ms7696 KiB
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	int l = 0, h = 1e9;
	while (l < h) {
		int m = (l + h) / 2;
		int SL = 0, SH = 0;
		for (int i = 0; i < N; i++) {
			SL += max(v[i] - m, 1ll);
			SH += v[i] + m;
		}
		if (SL <= N * K && SH >= N * K) {
			h = m;
		}
		else {
			l = m + 1;
		}
	}
	cout << l << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2024 KiB
subtask210/10
3Accepted3ms2240 KiB
4Accepted3ms2604 KiB
5Accepted3ms2968 KiB
6Accepted3ms3036 KiB
7Accepted3ms3044 KiB
8Accepted3ms3060 KiB
subtask320/20
9Accepted64ms5928 KiB
10Accepted64ms6056 KiB
11Accepted63ms6104 KiB
12Accepted63ms6212 KiB
13Accepted64ms6608 KiB
14Accepted64ms6432 KiB
15Accepted64ms6616 KiB
16Accepted64ms6612 KiB
17Accepted3ms3856 KiB
subtask424/24
18Accepted3ms4080 KiB
19Accepted3ms4092 KiB
20Accepted3ms4180 KiB
21Accepted3ms4172 KiB
22Accepted3ms4168 KiB
23Accepted3ms4276 KiB
24Accepted3ms4364 KiB
25Accepted3ms4356 KiB
26Accepted3ms4452 KiB
27Accepted3ms4484 KiB
28Accepted3ms4560 KiB
subtask546/46
29Accepted64ms7540 KiB
30Accepted68ms7496 KiB
31Accepted41ms6276 KiB
32Accepted61ms6928 KiB
33Accepted75ms7636 KiB
34Accepted75ms7696 KiB
35Accepted78ms7636 KiB
36Accepted78ms7632 KiB
37Accepted76ms7512 KiB
38Accepted75ms7564 KiB
39Accepted28ms5432 KiB
40Accepted4ms4720 KiB
41Accepted3ms4824 KiB