본문으로 바로가기

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]));
		}
	}
}

 

최저 높이와 최고 높이의 인덱스(위치)는 알 필요가 없기 때문에

최저 높이와 최고 높이의 높이만 바꿔주는 방법으로 구현했습니다.