65372023-12-07 22:17:05TuruTamasPontos Átlagcpp17Wrong answer 0/10097ms7824 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 (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
1Accepted3ms1884 KiB
2Accepted3ms2072 KiB
subtask20/20
3Accepted3ms2288 KiB
4Wrong answer3ms2628 KiB
5Accepted3ms2740 KiB
6Accepted3ms2944 KiB
7Accepted3ms3140 KiB
8Accepted3ms3212 KiB
9Accepted3ms3348 KiB
10Accepted3ms3560 KiB
11Accepted3ms3796 KiB
12Accepted3ms3796 KiB
13Accepted3ms3760 KiB
subtask30/40
14Wrong answer3ms3768 KiB
15Accepted3ms3916 KiB
16Accepted3ms3796 KiB
17Accepted3ms3948 KiB
18Accepted3ms3924 KiB
19Accepted3ms4008 KiB
20Accepted3ms4004 KiB
21Accepted3ms4236 KiB
22Accepted3ms4248 KiB
23Accepted3ms4148 KiB
24Accepted3ms4152 KiB
25Accepted3ms4148 KiB
26Accepted3ms4296 KiB
subtask40/40
27Wrong answer92ms7232 KiB
28Accepted97ms7232 KiB
29Accepted92ms7232 KiB
30Accepted92ms7228 KiB
31Accepted92ms7380 KiB
32Accepted93ms7236 KiB
33Accepted94ms7356 KiB
34Accepted93ms7336 KiB
35Accepted93ms7236 KiB
36Accepted82ms7364 KiB
37Accepted71ms7236 KiB
38Accepted43ms7232 KiB
39Accepted89ms7444 KiB
40Accepted90ms7440 KiB
41Accepted68ms7444 KiB
42Accepted90ms7720 KiB
43Accepted64ms7824 KiB