-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboj_2822.java
More file actions
48 lines (37 loc) · 1.14 KB
/
boj_2822.java
File metadata and controls
48 lines (37 loc) · 1.14 KB
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
42
43
44
45
46
47
48
package sorting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
public class boj_2822 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int arr[][]=new int[8][2];
for(int i=0;i<8;i++){
arr[i][0]=Integer.parseInt(br.readLine());
arr[i][1]=i+1;
}
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return Integer.compare(o2[0], o1[0]);
}
});
StringBuilder sb = new StringBuilder();
ArrayList<Integer> index = new ArrayList<>();
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += arr[i][0];
index.add(arr[i][1]);
}
Collections.sort(index);
for(int i:index) {
sb.append(i+" ");
}
System.out.println(sum);
System.out.println(sb);
}
}