https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV139KOaABgCFAYh
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.util.Arrays;
public class Solution {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
for (int t = 1; t <= 10; t++) {
int dump = scanner.nextInt(); // 1<= 덤프 횟수 <=1000
int[] high = new int[100]; // 상자의 높이
for (int i = 0; i < high.length; i++)
high[i] = scanner.nextInt();
for (int i = 0; i < dump; i++) {
Arrays.sort(high);
high[0]++;
high[high.length-1]--;
}
Arrays.sort(high);
System.out.println("#" + t + " " + (high[high.length-1] - high[0]));
}
}
}
최저 높이와 최고 높이의 인덱스(위치)는 알 필요가 없기 때문에
최저 높이와 최고 높이의 높이만 바꿔주는 방법으로 구현했습니다.
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
| [Algorithm] SWEA 2001 파리 퇴치 (0) | 2021.08.04 |
|---|---|
| [Algorithm] SWEA 1873 상호의 배틀필드 (0) | 2021.08.04 |
| [Algorithm] SWEA 1289 원재의 메모리 복구하기 (0) | 2021.08.04 |
| [Algorithm] 백준 17478 재귀함수가 뭔가요? (0) | 2021.08.04 |
| [Algorithm] 백준 1244 스위치 켜고 끄기 (0) | 2021.08.04 |