Submission #28315

# Submission time Handle Problem Language Result Execution time Memory
28315 2017-07-16T04:38:46 Z ㅁㄴㅇㄹ호(#1227, gs13105) Wine Tasting (FXCUP2_wine) C++14
0 / 1
0 ms 2288 KB
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

int arr[300000];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, k, i;
    long long res;
    scanf("%d%d", &n, &k);

    for(i = 0; i<n; i++)
        scanf("%d", &arr[i]);

    sort(arr, arr+n);

    res = arr[n-1];

    k = min(k, (n-1)/2 + 1);

    for(i = 1; i<k; i++)
    {
        if(i % 2 == 0)
            res += arr[n-1-i/2] - arr[i/2-1];
    }
    printf("%lld", res);
    return 0;
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:21:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
                          ^
wine.cpp:24:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2288 KB Output is correct
2 Correct 0 ms 2288 KB Output is correct
3 Incorrect 0 ms 2288 KB Output isn't correct
4 Halted 0 ms 0 KB -