67122023-12-17 18:22:46MagyarKendeSZLGPontos Átlagcpp17Wrong answer 0/10045ms6144 KiB
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

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

    int N, K, sum;
    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;
    
    if (prod == sum) {
        cout << 0 << endl;
    } else if (prod > sum || N == 1) {
        cout << 1 << endl;
    } else if (N == 2) {
        if (prod > max(P[0], P[1]) + 1e6 || prod < min(P[0], P[1]) + 1) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    } else {
        sort(P.begin(), P.end());
        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
1Accepted3ms1824 KiB
2Accepted3ms2020 KiB
subtask20/20
3Accepted3ms2232 KiB
4Accepted3ms2440 KiB
5Wrong answer3ms2656 KiB
6Accepted3ms2884 KiB
7Accepted3ms3100 KiB
8Accepted3ms3308 KiB
9Accepted3ms3524 KiB
10Wrong answer3ms3376 KiB
11Accepted3ms3504 KiB
12Accepted3ms3588 KiB
13Accepted3ms3716 KiB
subtask30/40
14Accepted3ms3800 KiB
15Accepted3ms3892 KiB
16Accepted3ms3808 KiB
17Accepted3ms3808 KiB
18Accepted3ms3936 KiB
19Accepted3ms4016 KiB
20Wrong answer3ms4020 KiB
21Wrong answer3ms4112 KiB
22Accepted3ms4108 KiB
23Accepted3ms4164 KiB
24Wrong answer3ms4024 KiB
25Accepted3ms4028 KiB
26Wrong answer3ms4032 KiB
subtask40/40
27Wrong answer45ms5612 KiB
28Partially correct45ms5812 KiB
29Wrong answer25ms5888 KiB
30Partially correct45ms5672 KiB
31Partially correct45ms5820 KiB
32Partially correct45ms5752 KiB
33Wrong answer25ms6008 KiB
34Partially correct45ms6076 KiB
35Partially correct45ms6144 KiB
36Wrong answer27ms5988 KiB
37Wrong answer45ms5992 KiB
38Accepted24ms5992 KiB
39Accepted43ms5884 KiB
40Wrong answer43ms5884 KiB
41Accepted35ms5884 KiB
42Wrong answer43ms5880 KiB
43Wrong answer34ms6028 KiB