[Codetree] 인접하지 않은 2개의 수
13 Sep 2026
Reading time ~1 minute
해당 문제는 코드트리 인접하지 않은 2개의 수에서 풀어보실 수 있습니다.
풀이 구현
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = sc.nextInt();
}
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++) {
for(int j = i+2; j < n; j++) {
max = Math.max(max,arr[i]+arr[j]);
}
}
System.out.println(max);
}
}