답안 #29032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29032 2017-07-18T07:12:17 Z cki86201 포도주 시음 (FXCUP2_wine) C++11
1 / 1
103 ms 3072 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

void solve() {
	int n, k;
	int A[300030];
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++)scanf("%d", A+i);
	sort(A+1, A+1+n);
	int l = 1, r = n, t = 1;
	int p = 0; ll ans = 0;
	rep(a, k) {
		if(t) { ans += A[r--] - p; t ^= 1; }
		else { p = A[l++]; t ^= 1;}
	}
	printf("%lld\n", ans);
}

int main(){
	int tc = 1; // scanf("%d", &tc);
	for(int t=1;t<=tc;t++) {
		solve();
	}
	return 0;
};

Compilation message

wine.cpp: In function 'void solve()':
wine.cpp:37: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:38:39: 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);
                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3072 KB Output is correct
2 Correct 0 ms 3068 KB Output is correct
3 Correct 0 ms 3072 KB Output is correct
4 Correct 0 ms 3068 KB Output is correct
5 Correct 0 ms 3068 KB Output is correct
6 Correct 0 ms 3064 KB Output is correct
7 Correct 0 ms 3064 KB Output is correct
8 Correct 0 ms 3072 KB Output is correct
9 Correct 0 ms 3064 KB Output is correct
10 Correct 0 ms 3072 KB Output is correct
11 Correct 0 ms 3068 KB Output is correct
12 Correct 0 ms 3068 KB Output is correct
13 Correct 0 ms 3068 KB Output is correct
14 Correct 0 ms 3068 KB Output is correct
15 Correct 0 ms 3068 KB Output is correct
16 Correct 0 ms 3072 KB Output is correct
17 Correct 3 ms 3072 KB Output is correct
18 Correct 6 ms 3068 KB Output is correct
19 Correct 6 ms 3064 KB Output is correct
20 Correct 6 ms 3072 KB Output is correct
21 Correct 13 ms 3068 KB Output is correct
22 Correct 33 ms 3072 KB Output is correct
23 Correct 23 ms 3068 KB Output is correct
24 Correct 23 ms 3072 KB Output is correct
25 Correct 93 ms 3068 KB Output is correct
26 Correct 93 ms 3068 KB Output is correct
27 Correct 96 ms 3068 KB Output is correct
28 Correct 56 ms 3064 KB Output is correct
29 Correct 99 ms 3068 KB Output is correct
30 Correct 79 ms 3072 KB Output is correct
31 Correct 79 ms 3072 KB Output is correct
32 Correct 103 ms 3072 KB Output is correct
33 Correct 0 ms 3068 KB Output is correct
34 Correct 16 ms 3068 KB Output is correct