SWEA_D3_9229
π [D3_9229] νλΉμ΄μ Spot Mart
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static StringTokenizer st;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int tc = Integer.parseInt(br.readLine());
for(int T = 1; T <= tc; T++) {
sb.append("#").append(T).append(" ");
st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int max = 0;
int[] arr = new int[N];
st = new StringTokenizer(br.readLine(), " ");
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
for(int i=0; i<N; i++)
for(int j=i+1; j<N; j++) {
int sum = arr[i]+arr[j];
if(sum>M) {
continue;
}
else {
max = Math.max(max, sum);
}
}
if(max == 0) {
max = -1;
}
sb.append(max);
sb.append("\n");
}
System.out.println(sb);
}
}
π€ λμ μκ°
μ΄μ€ forλ¬Έμ ν΅ν΄ κ°λ¨ν νλ Έλ€
μμ κ²μμ λΆλΆμ§ν© ν©μ μ¬μ©ν΄μ νμμΌλ©΄ 곡λΆνλ κ²μ μμ©νλ κ²μ΄μλλ° λ¬Έμ μμ 2κ°λ§ μ ννλΌν΄μ κ°λ¨ν μ΄μ€ forλ¬ΈμΌλ‘ ꡬννμλ€.