12079 | 2024-11-30 12:19:05 | Dávid | Pontos átlag 2 | cpp17 | Accepted 100/100 | 126ms | 3528 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
2 | Accepted | 1ms | 500 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 1ms | 320 KiB | ||||
4 | Accepted | 1ms | 320 KiB | ||||
5 | Accepted | 1ms | 320 KiB | ||||
6 | Accepted | 1ms | 320 KiB | ||||
7 | Accepted | 1ms | 512 KiB | ||||
8 | Accepted | 1ms | 324 KiB | ||||
subtask3 | 20/20 | ||||||
9 | Accepted | 64ms | 3384 KiB | ||||
10 | Accepted | 65ms | 3384 KiB | ||||
11 | Accepted | 63ms | 3228 KiB | ||||
12 | Accepted | 64ms | 3228 KiB | ||||
13 | Accepted | 65ms | 3384 KiB | ||||
14 | Accepted | 65ms | 3384 KiB | ||||
15 | Accepted | 68ms | 3384 KiB | ||||
16 | Accepted | 74ms | 3512 KiB | ||||
17 | Accepted | 1ms | 320 KiB | ||||
subtask4 | 24/24 | ||||||
18 | Accepted | 1ms | 320 KiB | ||||
19 | Accepted | 1ms | 320 KiB | ||||
20 | Accepted | 1ms | 320 KiB | ||||
21 | Accepted | 1ms | 320 KiB | ||||
22 | Accepted | 2ms | 388 KiB | ||||
23 | Accepted | 1ms | 320 KiB | ||||
24 | Accepted | 1ms | 320 KiB | ||||
25 | Accepted | 1ms | 320 KiB | ||||
26 | Accepted | 1ms | 320 KiB | ||||
27 | Accepted | 1ms | 396 KiB | ||||
28 | Accepted | 1ms | 320 KiB | ||||
subtask5 | 46/46 | ||||||
29 | Accepted | 68ms | 3516 KiB | ||||
30 | Accepted | 89ms | 3512 KiB | ||||
31 | Accepted | 61ms | 2040 KiB | ||||
32 | Accepted | 82ms | 2988 KiB | ||||
33 | Accepted | 111ms | 3384 KiB | ||||
34 | Accepted | 119ms | 3488 KiB | ||||
35 | Accepted | 116ms | 3508 KiB | ||||
36 | Accepted | 126ms | 3528 KiB | ||||
37 | Accepted | 126ms | 3504 KiB | ||||
38 | Accepted | 107ms | 3300 KiB | ||||
39 | Accepted | 43ms | 1480 KiB | ||||
40 | Accepted | 3ms | 436 KiB | ||||
41 | Accepted | 1ms | 320 KiB |