Skip to content

Commit aa89ce4

Browse files
committed
ps
1 parent 4ff98f7 commit aa89ce4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎TIL/J2798_2.java‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package TIL;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class J2798_2 {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
9+
10+
String[] input = buffer.readLine().split( " ");
11+
12+
int card = Integer.parseInt(input[0]);
13+
int key = Integer.parseInt(input[1]);
14+
int[] array = new int[card];
15+
16+
input = buffer.readLine().split( " ");
17+
18+
for(int i = 0; i< card; i++){
19+
array[i] = Integer.parseInt(input[i]);
20+
}
21+
Arrays.sort(array);
22+
int max = 0;
23+
24+
for(int i = 0; i < card-2; i++){
25+
for(int j = i+1; j< card-1; j++){
26+
for(int k = j+1; k< card; k++){
27+
int value = array[i]+array[j]+array[k];
28+
if(value <= key && max < value) {
29+
max = value;
30+
}
31+
}
32+
}
33+
}
34+
System.out.println(max);
35+
36+
}
37+
}

0 commit comments

Comments
 (0)