-
[1] 문제
[2] CODE
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); int[] arr = new int[N]; for (int i = 0; i < N; i++) { arr[i] = scan.nextInt(); } int result = search(arr, N, M); System.out.println(result); } static int search(int[] arr, int N, int M) { int result = 0; for (int i = 0; i < N - 2; i++) { // 자신 외의 2장의 카드는 J,K로 합하기에 // N-2 까지만 반복. for (int j = i + 1; j < N - 1; j++) { for (int k = j + 1; k < N; k++) { int temp = arr[i] + arr[j] + arr[k]; if (M == temp) { // 3개의 수를 더했을 때의 최대값 => Return return temp; } if(result < temp && temp < M) { result = temp; } } } } return result; } }
'PS > 백준' 카테고리의 다른 글
[백준_1946] 신입사원 (Greedy) (0) 2021.01.05 [백준_1541] 잃어버린 괄호 ( Greedy ) (0) 2021.01.05 [백준_2839] 설탕 배달 ( Greedy ) (0) 2021.01.05 [백준_10809] 알파벳 찾기 ( 문자열 ) (0) 2021.01.02 [백준_2309] 일곱난쟁이 (0) 2020.12.24 댓글