67152023-12-17 18:33:25MagyarKendeSZLGPontos Átlagcpp17Wrong answer 0/10046ms5840 KiB
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

const int LIM = 1e6;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, sum = 0;
    cin >> N >> K;
    
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        sum += P[i];
    }
    
    const int prod = N * K;

    sort(P.begin(), P.end());
    
    if (prod == sum) {
        cout << 0 << endl;
    } else if (N == 1) {
        cout << 1 << endl;
    } else if (N == 2) {
        if (prod > max(P[0], P[1]) + LIM || prod < min(P[0], P[1]) + 1) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    } else if (prod > sum) {
        for (int i = 0, result = 0; i < N; i++) {
            sum += LIM - P[i];
            result++;
            if (prod <= sum) {
                cout << result << endl;
                return 0;
            }
        }
    } else {
        for (int i = N - 1, result = 0; i >= 0; i--) {
            sum -= P[i] - 1;
            result++;
            if (prod >= sum) {
                cout << result << endl;
                return 0;
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted3ms1860 KiB
subtask20/20
3Accepted3ms2076 KiB
4Wrong answer3ms2288 KiB
5Accepted3ms2376 KiB
6Accepted3ms2376 KiB
7Accepted3ms2496 KiB
8Accepted3ms2584 KiB
9Accepted3ms2584 KiB
10Accepted3ms2984 KiB
11Accepted3ms2948 KiB
12Accepted3ms3304 KiB
13Accepted3ms3432 KiB
subtask30/40
14Wrong answer3ms3492 KiB
15Accepted3ms3664 KiB
16Accepted3ms3596 KiB
17Accepted3ms3700 KiB
18Accepted3ms3672 KiB
19Accepted3ms3736 KiB
20Accepted3ms3824 KiB
21Accepted3ms3836 KiB
22Accepted3ms3732 KiB
23Accepted3ms3732 KiB
24Accepted3ms3736 KiB
25Accepted3ms3736 KiB
26Accepted3ms3740 KiB
subtask40/40
27Wrong answer46ms5064 KiB
28Partially correct46ms5212 KiB
29Partially correct45ms5392 KiB
30Partially correct46ms5456 KiB
31Partially correct45ms5456 KiB
32Partially correct46ms5460 KiB
33Partially correct46ms5460 KiB
34Partially correct46ms5524 KiB
35Partially correct46ms5588 KiB
36Wrong answer30ms5480 KiB
37Accepted46ms5484 KiB
38Accepted24ms5480 KiB
39Accepted43ms5732 KiB
40Accepted43ms5820 KiB
41Accepted35ms5828 KiB
42Accepted45ms5840 KiB
43Accepted34ms5836 KiB