-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSolution.java
36 lines (28 loc) Β· 1.11 KB
/
Solution.java
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
package Combination.swea9229;
import java.io.*;
import java.util.*;
public class Solution {
static int TC, N, M;
static int[] arr;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Combination/swea9229/sample_input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
TC = Integer.parseInt(br.readLine());
for (int t = 1; t <= TC; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
arr = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken());
int ans = -1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N && i != j; j++) {
if (arr[i] + arr[j] > M) continue;
ans = Math.max(ans, arr[i] + arr[j]);
}
}
System.out.println("#" + t + " " + ans);
}
}
}