116322024-11-02 10:04:37MagyarKendeSZLGPontos átlag 2cpp17Wrong answer 10/10041ms1860 KiB
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
#define int long long

int32_t main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int& x : p) cin >> x;

    int goal = N * K;
    int avg = accumulate(p.begin(), p.end(), 0LL);

    if (goal == avg) {
        cout << "0\n";
        exit(0);
    }

    auto f = [&](int c) -> bool {
        if (goal == avg) { return 1; }
        if (goal > avg) { return avg + N * c >= goal; }
        int d = 0;
        for (int x : p) { d += min(x - 1, c); }
        return avg - d <= goal;
    };

    int l = -1, r = 1e18;
    while (r - l > 1) {
        int m = (r + l) / 2;
        if (f(m)) {
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
subtask210/10
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted1ms320 KiB
7Accepted1ms320 KiB
8Accepted1ms320 KiB
subtask30/20
9Wrong answer16ms1848 KiB
10Accepted27ms1848 KiB
11Accepted14ms1848 KiB
12Accepted27ms1848 KiB
13Wrong answer16ms1848 KiB
14Accepted28ms1848 KiB
15Accepted27ms1848 KiB
16Accepted27ms1848 KiB
17Wrong answer1ms320 KiB
subtask40/24
18Accepted1ms320 KiB
19Accepted1ms344 KiB
20Accepted1ms320 KiB
21Accepted1ms320 KiB
22Accepted1ms500 KiB
23Wrong answer1ms540 KiB
24Wrong answer1ms320 KiB
25Accepted1ms508 KiB
26Accepted1ms508 KiB
27Accepted1ms320 KiB
28Wrong answer1ms508 KiB
subtask50/46
29Accepted27ms1848 KiB
30Accepted32ms1848 KiB
31Accepted20ms1080 KiB
32Wrong answer20ms1596 KiB
33Accepted37ms1848 KiB
34Accepted39ms1848 KiB
35Accepted28ms1848 KiB
36Accepted41ms1848 KiB
37Accepted41ms1848 KiB
38Wrong answer26ms1860 KiB
39Accepted14ms828 KiB
40Accepted2ms320 KiB
41Wrong answer1ms320 KiB