11023 | 2024-06-15 23:09:32 | matekimado11 | Pontos átlag 2 | cpp17 | Accepted 100/100 | 111ms | 3300 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
// FĂĽggvĂ©ny, amely ellenĹ‘rzi, hogy egy adott C Ă©rtĂ©kkel megvalĂłsĂthatĂł-e az elvárt átlag
bool canAchieveWithC(const vector<int>& prices, int N, int K, long long C) {
long long min_possible_sum = 0;
long long max_possible_sum = 0;
for (int price : prices) {
min_possible_sum += max(price - C, 1LL); // Az ár nem csökkenhet 1 alá
max_possible_sum += price + C;
}
long long target_sum = static_cast<long long>(N) * K;
return min_possible_sum <= target_sum && target_sum <= max_possible_sum;
}
int main() {
int N, K;
cin >> N >> K;
vector<int> prices(N);
for (int i = 0; i < N; ++i) {
cin >> prices[i];
}
// Bináris keresés a legkisebb C megtalálásához
long long low = 0;
long long high = 1000000000; // Nagy kezdőérték a high számára
long long result = high;
while (low <= high) {
long long mid = (low + high) / 2;
if (canAchieveWithC(prices, N, K, mid)) {
result = mid; // Ha lehetséges, próbáljuk meg kisebb C értékkel
high = mid - 1;
} else {
low = mid + 1; // Ha nem lehetséges, növeljük C értékét
}
}
cout << result << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 356 KiB | ||||
2 | Accepted | 3ms | 416 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 508 KiB | ||||
4 | Accepted | 3ms | 532 KiB | ||||
5 | Accepted | 3ms | 664 KiB | ||||
6 | Accepted | 3ms | 520 KiB | ||||
7 | Accepted | 3ms | 356 KiB | ||||
8 | Accepted | 2ms | 356 KiB | ||||
subtask3 | 20/20 | ||||||
9 | Accepted | 46ms | 1636 KiB | ||||
10 | Accepted | 45ms | 1520 KiB | ||||
11 | Accepted | 43ms | 1412 KiB | ||||
12 | Accepted | 43ms | 1568 KiB | ||||
13 | Accepted | 46ms | 1512 KiB | ||||
14 | Accepted | 45ms | 1440 KiB | ||||
15 | Accepted | 45ms | 1784 KiB | ||||
16 | Accepted | 45ms | 1552 KiB | ||||
17 | Accepted | 3ms | 356 KiB | ||||
subtask4 | 24/24 | ||||||
18 | Accepted | 3ms | 428 KiB | ||||
19 | Accepted | 3ms | 656 KiB | ||||
20 | Accepted | 3ms | 616 KiB | ||||
21 | Accepted | 3ms | 384 KiB | ||||
22 | Accepted | 3ms | 376 KiB | ||||
23 | Accepted | 3ms | 484 KiB | ||||
24 | Accepted | 3ms | 376 KiB | ||||
25 | Accepted | 3ms | 500 KiB | ||||
26 | Accepted | 3ms | 504 KiB | ||||
27 | Accepted | 3ms | 356 KiB | ||||
28 | Accepted | 3ms | 360 KiB | ||||
subtask5 | 46/46 | ||||||
29 | Accepted | 46ms | 1600 KiB | ||||
30 | Accepted | 68ms | 1948 KiB | ||||
31 | Accepted | 48ms | 1676 KiB | ||||
32 | Accepted | 67ms | 2192 KiB | ||||
33 | Accepted | 86ms | 2848 KiB | ||||
34 | Accepted | 92ms | 3228 KiB | ||||
35 | Accepted | 98ms | 3300 KiB | ||||
36 | Accepted | 100ms | 3044 KiB | ||||
37 | Accepted | 111ms | 3116 KiB | ||||
38 | Accepted | 86ms | 2752 KiB | ||||
39 | Accepted | 35ms | 1380 KiB | ||||
40 | Accepted | 4ms | 632 KiB | ||||
41 | Accepted | 3ms | 504 KiB |