반응형
https://www.acmicpc.net/problem/2798
import java.util.Scanner;
public class Main {
static int N, M, answer = -999999;
static int[] arr, temp;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
arr = new int[N];
temp = new int[N];
for(int i=0; i<N; i++) {
arr[i] = sc.nextInt();
}
recur(0, 0);
System.out.println(answer);
}
public static void recur(int start, int depth) {
if(depth == 3) {
int sum =0;
for(int i=0; i<3; i++) {
sum += temp[i];
}
if(sum <= M) answer = Math.max(answer, sum);
return;
}
for(int i=start; i<N; i++) {
temp[depth] = arr[i];
recur(i+1, depth+1);
}
}
}
반응형
'알고리즘 > 문제풀이' 카테고리의 다른 글
[백준] 7568. 덩치 (0) | 2020.01.26 |
---|---|
[백준] 2231. 분해합 (0) | 2020.01.26 |
[SWEA] 1210. [S/W 문제해결 기본] 2일차 - Ladder1 (0) | 2020.01.25 |
[SWEA] 5215.햄버거 다이어트 (0) | 2020.01.25 |
[SWEA] 1289.원재의 메모리 복구하기 (0) | 2020.01.25 |