SWEA_4466) 최대 성적표 만들기

4466) 최대 성적표 만들기 (19.10.21)


문제 링크 (SW Expert Academy)

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
36
37
import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer tk;
        
        int test = Integer.parseInt(br.readLine());
        for(int t=1; t<=test; t++) {
            tk = new StringTokenizer(br.readLine());
            
            int n = Integer.parseInt(tk.nextToken());
            int k = Integer.parseInt(tk.nextToken());
            
            int[] arr = new int[n];
            tk = new StringTokenizer(br.readLine());
            
            for(int i=0;i<n;i++) {
                arr[i] = Integer.parseInt(tk.nextToken());
            }
            
            Arrays.sort(arr);
            
            int sum = 0;
            for(int i=n-1;i>=n-k; i--) {
                sum = sum+arr[i];
            }
            
            bw.write("#" + t + " " + sum + "\n");
        }
        
        bw.flush();
        bw.close();
    }
}
cs




댓글

이 블로그의 인기 게시물