65382023-12-07 22:27:20TuruTamasPontos Átlagcpp17Accepted 100/10093ms8080 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#else
#define input cin
#endif
typedef long long ll;

ll N, K, ossz;
ll P[200'000];

int main() {
    input >> N >> K;
    K *= N;
    for (int n = 0; n < N; n++) {
        input >> P[n];
        ossz += P[n];
    }
    if (K > ossz) {
        cout << 1 << endl;
        exit(0);
    }
    if (ossz == K) {
        cout << 0 << endl;
        exit(0);
    }
    if (N == 1) {
        cout << 1 << endl;
        exit(0);
    }
    if (N == 2) {
        // cout << K << " " << P[0] << " " << P[1] << endl;
        if (K > max(P[0], P[1])+1'000'000)
            cout << 2 << endl;
        else if (K < min(P[0], P[1])+1) {
            cout << 2 << endl;
        }
        else
            cout << 1 << endl;
        exit(0);
    }
    sort(P, P+N);
    ll r = 0;
    if (K > ossz) {
        for (ll i = 0; i < N; i++) {
            ossz += 1'000'000-P[i];
            r++;
            if (ossz >= K) {
                cout << r << endl;
                exit(0);
            }
        }
    }
    else {
        for (ll i = N-1; i >= 0; i--) {
            ossz -= P[i]-1;
            r++;
            if (ossz <= K) {
                cout << r << endl;
                exit(0);
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2032 KiB
2Accepted3ms2260 KiB
subtask220/20
3Accepted3ms2480 KiB
4Accepted3ms2484 KiB
5Accepted3ms2784 KiB
6Accepted3ms2756 KiB
7Accepted3ms2860 KiB
8Accepted3ms3000 KiB
9Accepted3ms3208 KiB
10Accepted3ms3440 KiB
11Accepted3ms3588 KiB
12Accepted3ms3584 KiB
13Accepted3ms3580 KiB
subtask340/40
14Accepted3ms3660 KiB
15Accepted3ms3728 KiB
16Accepted4ms3920 KiB
17Accepted3ms3992 KiB
18Accepted3ms4100 KiB
19Accepted3ms3964 KiB
20Accepted3ms4108 KiB
21Accepted3ms4236 KiB
22Accepted3ms4204 KiB
23Accepted3ms4204 KiB
24Accepted3ms4252 KiB
25Accepted3ms4224 KiB
26Accepted3ms4316 KiB
subtask440/40
27Accepted71ms7560 KiB
28Accepted93ms7696 KiB
29Accepted93ms7696 KiB
30Accepted93ms7676 KiB
31Accepted93ms7676 KiB
32Accepted93ms7676 KiB
33Accepted93ms7680 KiB
34Accepted93ms7764 KiB
35Accepted93ms7724 KiB
36Accepted85ms7888 KiB
37Accepted71ms8020 KiB
38Accepted46ms8080 KiB
39Accepted90ms7928 KiB
40Accepted93ms7936 KiB
41Accepted71ms7932 KiB
42Accepted92ms7932 KiB
43Accepted64ms7932 KiB