답안 #28284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28284 2017-07-16T04:23:50 Z 점수판에 아이디와 팀명이 같이 표기되니, 신중하게 적어주세요.(#1186, kajebiii, secsegy, woqja125) 포도주 시음 (FXCUP2_wine) C++14
1 / 1
113 ms 3192 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 3e5 + 100;

int N, K, Nr[MAX_N];

int main() {
	cin >> N >> K;
	for(int i=0; i<N; i++) scanf("%d", &Nr[i]);
	sort(Nr, Nr+N);
	int l = 0, r = N-1, last = 0;
	ll ans = 0;
	for(int i=0; i<K; i++) {
		if(i % 2 == 0) {
			ans += Nr[r] - last;
			last = Nr[r]; r--;
		} else {
			ans += 0;
			last = Nr[l]; l++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:22:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<N; i++) scanf("%d", &Nr[i]);
                                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3192 KB Output is correct
2 Correct 0 ms 3192 KB Output is correct
3 Correct 0 ms 3192 KB Output is correct
4 Correct 0 ms 3192 KB Output is correct
5 Correct 0 ms 3192 KB Output is correct
6 Correct 0 ms 3192 KB Output is correct
7 Correct 0 ms 3192 KB Output is correct
8 Correct 0 ms 3192 KB Output is correct
9 Correct 0 ms 3192 KB Output is correct
10 Correct 0 ms 3192 KB Output is correct
11 Correct 0 ms 3192 KB Output is correct
12 Correct 0 ms 3192 KB Output is correct
13 Correct 0 ms 3192 KB Output is correct
14 Correct 0 ms 3192 KB Output is correct
15 Correct 0 ms 3192 KB Output is correct
16 Correct 0 ms 3192 KB Output is correct
17 Correct 3 ms 3192 KB Output is correct
18 Correct 3 ms 3192 KB Output is correct
19 Correct 6 ms 3192 KB Output is correct
20 Correct 6 ms 3192 KB Output is correct
21 Correct 16 ms 3192 KB Output is correct
22 Correct 23 ms 3192 KB Output is correct
23 Correct 23 ms 3192 KB Output is correct
24 Correct 19 ms 3192 KB Output is correct
25 Correct 96 ms 3192 KB Output is correct
26 Correct 83 ms 3192 KB Output is correct
27 Correct 99 ms 3192 KB Output is correct
28 Correct 56 ms 3192 KB Output is correct
29 Correct 113 ms 3192 KB Output is correct
30 Correct 103 ms 3192 KB Output is correct
31 Correct 79 ms 3192 KB Output is correct
32 Correct 83 ms 3192 KB Output is correct
33 Correct 0 ms 3192 KB Output is correct
34 Correct 13 ms 3192 KB Output is correct