https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW8Wj7cqbY0DFAXN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
public class Main_SWEA_9229_한빈이와SpotMart {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int TC = scanner.nextInt();
for (int tc = 1; tc <= TC; tc++) {
int N = scanner.nextInt(); // 과자 봉지의 개수
int M = scanner.nextInt(); // 과자 봉지 무게 합 제한
int[] snacks = new int[N];
for (int n = 0; n < N; n++)
snacks[n] = scanner.nextInt();
int max = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (snacks[i] + snacks[j] <= M)
max = Math.max(max, snacks[i] + snacks[j]);
}
}
System.out.print("#" + tc + " ");
if (max == 0)
System.out.println(-1);
else
System.out.println(max);
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] SWEA 1210 Ladder1 (0) | 2021.08.10 |
---|---|
[Algorithm] SWEA 1229 암호문1 (0) | 2021.08.09 |
[Algorithm] 백준 1018 체스판 다시 칠하기 (0) | 2021.08.09 |
[Algorithm] 백준 7568 덩치 (0) | 2021.08.08 |
[Algorithm] 백준 2231 분해합 (0) | 2021.08.08 |