115712024-10-27 08:23:59chucknorrisPontos Átlagcpp17Accepted 100/10046ms1260 KiB
// NOTE: it is recommended to use this even if you don't understand the following code.

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    // uncomment the two following lines if you want to read/write from files
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vector<int> P(N);
    for (int i = 0; i < N; ++i)
        cin >> P[i];

    int ans = 0;

    long long S = 0;
    for (int i = 0; i < N; ++i) S = S + P[i];
    if(S == 1LL * K * N) cout << 0;
    else if(S < 1LL * K * N) cout << 1;///eleg csak 1-et annyival emelni, hogy meglegyen a kert atlag
    else{
        sort(P.begin(), P.end());
        ///a legnagybbat csokkentjuk
        for(int i = N - 1; i >= 0 and S > 1LL * K * N; i--){
            if(S - P[i] + 1 > 1LL * K * N){
                ans = ans + 1; S = S - P[i] + 1;
            }
            else{
                ans = ans + 1; S = 0;
            }
        }
       cout << ans << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms500 KiB
subtask220/20
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted1ms320 KiB
7Accepted1ms320 KiB
8Accepted1ms320 KiB
9Accepted1ms544 KiB
10Accepted1ms320 KiB
11Accepted1ms320 KiB
12Accepted1ms320 KiB
13Accepted1ms320 KiB
subtask340/40
14Accepted1ms320 KiB
15Accepted1ms320 KiB
16Accepted1ms508 KiB
17Accepted1ms320 KiB
18Accepted1ms376 KiB
19Accepted1ms432 KiB
20Accepted1ms332 KiB
21Accepted1ms320 KiB
22Accepted1ms320 KiB
23Accepted1ms560 KiB
24Accepted1ms320 KiB
25Accepted1ms320 KiB
26Accepted1ms320 KiB
subtask440/40
27Accepted25ms1080 KiB
28Accepted46ms1220 KiB
29Accepted46ms1080 KiB
30Accepted46ms1084 KiB
31Accepted46ms1220 KiB
32Accepted46ms1168 KiB
33Accepted46ms1080 KiB
34Accepted46ms1084 KiB
35Accepted46ms1080 KiB
36Accepted30ms1224 KiB
37Accepted25ms1080 KiB
38Accepted21ms1228 KiB
39Accepted45ms1080 KiB
40Accepted45ms1080 KiB
41Accepted35ms1216 KiB
42Accepted45ms1228 KiB
43Accepted32ms1260 KiB