forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe4466.java
More file actions
42 lines (29 loc) · 892 Bytes
/
swe4466.java
File metadata and controls
42 lines (29 loc) · 892 Bytes
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
38
39
40
41
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class swe4466 {
static Scanner sc = new Scanner(System.in);
static ArrayList<Integer> AL;
public static void main(String[] args) {
int T = sc.nextInt();
int answer = 0;
for(int t=0; t<T; t++) {
int N = sc.nextInt();
int K = sc.nextInt();
AL = new ArrayList<>();
answer = Solution(N,K);
System.out.println("#" + (t + 1) + " " + answer);
}
}
public static int Solution(int N, int K)
{
int sum = 0;
for(int i = 0; i<N; i++)
AL.add(sc.nextInt());
Collections.sort(AL, Collections.reverseOrder());
for(int i =0; i<K; i++)
sum += AL.get(i);
return sum;
}
}