-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_2798.java
More file actions
32 lines (27 loc) · 1019 Bytes
/
Copy pathBJAlgo_2798.java
File metadata and controls
32 lines (27 loc) · 1019 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BJAlgo_2798 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] nm = br.readLine().split(" ");
int N = Integer.parseInt(nm[0]);
int M = Integer.parseInt(nm[1]);
int[] cards = new int[N];
String[] inputs = br.readLine().split(" ");
for (int i = 0; i < cards.length; i++) {
cards[i] = Integer.parseInt(inputs[i]);
}
int result = 0;
for (int i = 0; i < cards.length; i++) {
for (int j = i + 1; j < cards.length; j++) {
for (int k = j + 1; k < cards.length; k++) {
int sum = cards[i] + cards[j] + cards[k];
if (sum <= M && sum > result) {
result = sum;
}
}
}
}
System.out.println(result);
}
}