1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.util.Arrays; import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { // Scanner sc = new Scanner(new FileInputStream("sample_input.txt")); Scanner sc = new Scanner(System.in); int T; int test_case; T = sc.nextInt(); for (test_case = 1; test_case <= T; test_case++) { int n = sc.nextInt(); int k = sc.nextInt(); int score[] = new int[n]; int final_score = 0; for (int i = 0; i < n; i++) score[i] = sc.nextInt(); Arrays.sort(score); for (int i = 1; i <= k; i++) { final_score += score[n - i]; } System.out.println("Case #" + test_case); System.out.println(final_score); } } } | cs |
'공부 > 알고리즘문제' 카테고리의 다른 글
백준 1012 유기농 배추 (0) | 2017.04.13 |
---|---|
백준 13458 시험 감독 (0) | 2017.04.12 |
백준 14499 주사위 굴리기 (0) | 2017.04.12 |
코드그라운드 숫자 골라내기 (0) | 2017.04.11 |
코드그라운드 할인권 (0) | 2017.04.11 |