SWEA - 1208 : Flatten [자바]

HungAh.log·2021년 8월 12일
0
import java.util.*;
import java.io.*;

class Solution {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = 10; // 테스트 케이스 수
		for (int i = 0; i < T; i++) {
			int dump = Integer.parseInt(br.readLine());
			String[] s = br.readLine().split(" ");
			int[] box = new int[100];

			for (int j = 0; j < box.length; j++) {
				box[j] = Integer.parseInt(s[j]);
			}

			// 최대값 찾고 최소값 찾고~
			for (int j = 0; j < dump; j++) {
				Arrays.sort(box);

				if (box[99] - box[0] <= 1) {
					break;
				}
				box[99]--;
				box[0]++;
			}
			Arrays.sort(box);
			System.out.println("#" + (i + 1) + " " + (box[99] - box[0]));
		}
	}
}
profile
👩🏻‍💻

0개의 댓글

관련 채용 정보