/
SWAcademy 9229
46 lines (41 loc) · 1.04 KB
/
SWAcademy 9229
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
import java.io.*;
import java.util.*;
public class Solution {
static int[] kg, resert = new int[2];
static int N, M, MAX, SUM;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
MAX = 0;
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
kg = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
kg[i] = Integer.parseInt(st.nextToken());
}
comb(0, 0);
if(MAX == 0)
MAX--;
System.out.println("#" + t + " " + MAX);
}
}
static void comb(int start, int index) {
if (index == 2) {
for (int i = 0; i < 2; i++) {
SUM += resert[i];
}
if(SUM<=M)
MAX = Math.max(SUM, MAX);
SUM=0;
return;
}
for (int i = start; i < N; i++) {
resert[index] = kg[i];
comb(i + 1, index + 1);
}
}
}