문제 - 1208. Flatten(D3)
가장 높은 곳과 낮은 곳이 어디인지 판별하는 아이디어가 있었다면 쉬운 문제이다!
sort를 해주면 간단하게 판별 가능해진다.
import java.util.Scanner;
import java.io.FileInputStream;
import java.util.Arrays;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int[] boxes = new int[100];
for(int tc = 1; tc<=10; tc++) {
int dump = sc.nextInt();
for(int i=0; i<100; i++) {//박스 넣기
boxes[i] = sc.nextInt();
}
int result = 0;
for(int i=0; i<dump; i++) {//dump 횟수만큼 진행
Arrays.sort(boxes);//오름차순, 맨앞이 작은 수, 맨 뒤가 큰 수
if(boxes[99]-boxes[0]>= 2) {
boxes[99]--;
boxes[0]++;
}else if(boxes[99]-boxes[0] <=1){
break;
}
}
Arrays.sort(boxes);
result = boxes[99]-boxes[0];
System.out.println("#"+tc+" "+result);
}
}
}