77582024-01-11 08:03:21csdavidSípálya (55 pont)cpp17Wrong answer 0/5541ms9692 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, K;
    cin >> N >> K;
    vector<ll> H(N), prefix(N+1, 0);
    for(int i=0; i<N; i++) cin >> H[i];

    sort(H.begin(), H.end());

    for(int i=1; i<=N; i++) prefix[i] = prefix[i-1] + H[i-1];

    ll ans = 1e18;
    for(int i=K-1; i<N; i++) {
        ll cost = H[i]*1LL*K - (prefix[i+1] - prefix[i+1-K]);
        ans = min(ans, cost);
    }

    cout << ans << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms1824 KiB
2Wrong answer0/03ms2056 KiB
3Wrong answer0/23ms2424 KiB
4Wrong answer0/23ms2384 KiB
5Wrong answer0/23ms2652 KiB
6Wrong answer0/23ms2968 KiB
7Wrong answer0/33ms2864 KiB
8Wrong answer0/14ms3448 KiB
9Wrong answer0/14ms3376 KiB
10Wrong answer0/14ms3324 KiB
11Wrong answer0/14ms3328 KiB
12Wrong answer0/14ms3328 KiB
13Wrong answer0/14ms3580 KiB
14Wrong answer0/24ms3536 KiB
15Wrong answer0/24ms3664 KiB
16Wrong answer0/241ms9432 KiB
17Wrong answer0/239ms9464 KiB
18Wrong answer0/239ms9392 KiB
19Wrong answer0/339ms9420 KiB
20Wrong answer0/239ms9692 KiB
21Wrong answer0/239ms9540 KiB
22Wrong answer0/239ms9668 KiB
23Wrong answer0/239ms9608 KiB
24Wrong answer0/241ms9604 KiB
25Wrong answer0/239ms9608 KiB
26Wrong answer0/239ms9604 KiB
27Wrong answer0/239ms9632 KiB
28Wrong answer0/339ms9632 KiB
29Wrong answer0/339ms9652 KiB
30Wrong answer0/339ms9652 KiB