제출 #28285

#제출 시각아이디문제언어결과실행 시간메모리
28285Official Fan of ACG (#68)포도주 시음 (FXCUP2_wine)C++14
1 / 1
99 ms3104 KiB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	ll sum = 0;
	int last = 0, p = 0, q = n - 1;
	while (k > 1) {
		sum += (a[q--] - last);
		last = a[p++];
		k -= 2;
	}
	if (k == 1) sum += a[q] - last;
	printf("%lld\n", sum);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

wine.cpp: In function 'int main()':
wine.cpp:10:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
wine.cpp:13:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...