Submission #29353

#TimeUsernameProblemLanguageResultExecution timeMemory
29353jjwdi0Wine Tasting (FXCUP2_wine)C++11
1 / 1
119 ms3192 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll ans;
int N, K, A[300005];

int main() {
    scanf("%d %d", &N, &K);
    for(int i=1; i<=N; i++) scanf("%d", A+i);
    sort(A+1, A+N+1);
    int pre = 0;
    for(int i=1, s=1, e=N; i<=K; i++) {
        if(i & 1) {
            ans += A[e] - pre;
            pre = A[e--];
        }
        else pre = A[s++];
    }
    printf("%lld\n", ans);
}

Compilation message (stderr)

wine.cpp: In function 'int main()':
wine.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
                           ^
wine.cpp:10:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d", A+i);
                                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...