제출 코드
- 사용 알고리즘 :
조합
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
package bronze;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
public class B2798_blackjack {
static int N, M, result = -1;
static boolean back;
static Integer[] card;
static void comb(int n, int start, int sum) {
if(M < sum) return;
if(n==3) {
result = Math.max(result, sum);
return;
}
for(int i=start; i<N; i++) {
comb(n+1, i+1, sum+card[i]);
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] line = br.readLine().split(" ");
N = Integer.parseInt(line[0]);
M = Integer.parseInt(line[1]);
line = br.readLine().split(" ");
card = new Integer[N];
for(int i=0; i<N; i++) card[i] = Integer.parseInt(line[i]);
Arrays.sort(card, Collections.reverseOrder());
comb(0, 0, 0);
System.out.println(result);
}
}