Submission #28590

# Submission time Handle Problem Language Result Execution time Memory
28590 2017-07-16T07:44:40 Z 탕탕탕! 핑거팁 니 맘을 겨눌게~(#1190, cls327, archane5276, ly0829) Wine Tasting (FXCUP2_wine) C
0 / 1
0 ms 3460 KB
#include <stdio.h>

int wine[300000], flag[300000];

int main() {
	int N, K, i, j, min, max, pre_min, min_index, max_index;
	long long int flavor = 0;
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++)
		scanf("%d", &wine[i]);
	i = 0;
	while (i < K) {
		min = 1000000001, max = -1;
		for (j = 0; j < N; j++) {
			if (max < wine[j] && flag[j] == 0) { max = wine[j]; max_index = j; }
			if (min > wine[j] && flag[j] == 0) { min = wine[j]; min_index = j; }
		}
		flag[max_index] = 1, flag[min_index] = 1;
		if (i == 0) {
			flavor = max;
			pre_min = min;
			i++;
			continue;
		}
		else flavor += (max - pre_min);
		pre_min = min;
		i = i + 2;
	}
	printf("%lld", flavor);
}

Compilation message

wine.c: In function 'main':
wine.c:8:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:10:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &wine[i]);
   ^
wine.c:18:19: warning: 'max_index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   flag[max_index] = 1, flag[min_index] = 1;
                   ^
wine.c:18:40: warning: 'min_index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   flag[max_index] = 1, flag[min_index] = 1;
                                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Incorrect 0 ms 3460 KB Output isn't correct
4 Halted 0 ms 0 KB -