SWEA_D3_1208
π [D3_1208] Flatten
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int t = 1; t <= 10; t++) {
int dump_cnt = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
int max,min,result;
//κ° μ
λ ₯
for (int i = 0; i < 100; i++) {
arr.add(sc.nextInt());
}
//ννν μμ
for(int i=0; i<dump_cnt;i++) {
//μ λ ¬ ν / μ²μ κ° : μ΅μκ° / λ§μ§λ§ κ° : μ΅λκ°
Collections.sort(arr);
max = arr.get(99);
min = arr.get(0);
//ννν μμ
max -= 1;
min += 1;
//ννν μμ
ν κ° λ³κ²½
arr.set(99,max);
arr.set(0, min);
}
//λ§μ§λ§μ μ λ ¬ νλ² λ !
Collections.sort(arr);
//μ΅λκ° - μ΅μκ°
result = arr.get(99)-arr.get(0);
System.out.println("#" + t + " " + result);
}
}
}
π€ λμ μκ°
μ΄ λ¬Έμ μ ν΅μ¬μ μ μΌ μ²μ μ λ ¬μ΄κΈ°λ νμ§λ§ λ§μ§λ§μ ν λ²λ ν΄μ£Όλ μ λ ¬μΈ κ² κ°λ€.
λ§μ§λ§μ μ λ ¬μ μν΄μ£Όλ©΄ κ°μ΄ λ€λ₯Ό μλ μκΈ° λλ¬Έμ΄λ€.
ArrayListμ sortλ₯Ό μ°λ©΄ κ°λ¨νκ² ν릴 λ¬Έμ !!