Problem:
Score : 200 points

Problem Statement

Snuke has N sticks.
The length of the i-th stick is l_i.

Snuke is making a snake toy by joining K of the sticks together.

The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

Constraints

1 \leq K \leq N \leq 50

1 \leq l_i \leq 50

l_i is an integer.

Input

Input is given from Standard Input in the following format:

N K
l_1 l_2 l_3 ... l_{N}

Output

Print the answer.

Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

Sample Input 2

15 14
50 26 27 21 41 7 42 35 7 5 5 36 39 1 45

Sample Output 2

386

Solution in C (Clang 3.8.0) (judge verdict: Accepted)

/*
 ============================================================================
 Name        : atcorder_002.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {

	int n,k;
	int l[50];
	int i, j, t, tmp, total = 0;

	scanf("%d", &n);
	if(n > 50 || n <= 0) {
		printf("1-50の整数を入力ください\n");
		return EXIT_FAILURE;
	}

	scanf("%d", &k);
	if(k > 50 || k <= 0) {
		printf("1-50の整数を入力ください\n");
		return EXIT_FAILURE;
	}


	if(n < k) {
		printf("エラー。N < K になっています。最初の入力値 >= 後の入力値 にしてください。\n");
		return EXIT_FAILURE;
	}
	for (i = 0; i < n; ++i) {
		scanf("%d", &l[i]);

		if(l[i] > 50){
			printf("エラー。棒の長さは50以下を指定ください。\n");
			return EXIT_FAILURE;
		}
	}


	/* 数値を昇順にソート */
	for (t = 0; t < n; ++t) {
		for (j = t + 1; j < n; ++j) {
			if (l[t] > l[j]) {
				tmp = l[t];
				l[t] = l[j];
				l[j] = tmp;
			}
		}
	}
	/*
	printf("昇順sortした数値\n");
	for (i=0; i<n; ++i){
	    printf("%d\n", l[i]);
	}
	*/
	for (int t = n-1; 0 < k ; --t, --k) {
		total += l[t];
	}
	printf("%d\n", total);

}