JAVA 알고리즘

1208. [S/W 문제해결 기본] 1일차 - Flatten

잡다한 저장소 2019. 8. 28. 22:36
import java.util.Arrays;

import java.util.Scanner;



public class Solution {



    public static void main(String[] args) {

        

        Scanner sc = new Scanner(System.in);

        for(int tc = 1; tc <= 10; tc++) {

            

            // 입력

            int dump = sc.nextInt();

            int[] box = new int[100];

            for(int i = 0; i < 100; i++) {

                box[i] = sc.nextInt();

            }

            

            int max = 0, min = 999, result = 0;

 Arrays.sort(box); // 오름차순으로 정렬 해주고

            for(int j = 0; j < dump; j++) {

                Arrays.sort(box); // dump동안 계속 정렬

                box[0]++; // 처음값이 최소값이므로 ++

                box[99]--; // 끝값이 최대값이므로 --

            }

            

            for(int l = 0; l < 100; l++) { // dump를 끝낸 배열에서

                if(max < box[l]) { // 최대값을 저장

                    max = box[l];

                }

                if(min > box[l]) { // 최소값을 저장

                    min = box[l];

                }

            }

            

            result = max - min; // 결과를 저장

            System.out.println("#" + tc + " " + result);

            

            

        } // end of tc

        

        

    } // end of main



}