https://www.acmicpc.net/problem/2798
: 카드 3장의 합,근데 이제 M을 넘지 않는.
import java.util.*;
import java.io.*;
public class Main {
static int N,M;
static int[] arr;
static Boolean[] visited;
static int MaxResult = Integer.MIN_VALUE;
public static void main(String[] args) throws IOException{
// 값 입력받기 -->
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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());
}
//<--
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
for(int k=j+1;k<N;k++){
int ans = arr[i] + arr[j] + arr[k];
if (ans> MaxResult && ans<=M) {
MaxResult = Math.max(MaxResult,ans);
}
}
}
}
System.out.println(MaxResult);
}
}
썸넬출처 : https://m.post.naver.com/viewer/postView.nhn?volumeNo=14677615&memberNo=5733106