import
java.util.Scanner;
class
Solution {
static
int
Answer;
public
static
void
main(String args[])
throws
Exception {
Scanner sc =
new
Scanner(System.in);
for
(
int
T=
1
; T <=
10
; T++) {
// dump 횟수
int
dumpCount = sc.nextInt();
sc.nextLine();
// 숫자 리스트
String[] strNumList = sc.nextLine().trim().split(
" "
);
int
[] countArr =
new
int
[
101
];
// 0 ~ 100
// 각각의 숫자들을 카운팅
int
min=
101
, max=
0
;
for
(String strNum : strNumList) {
int
height = Integer.parseInt(strNum);
countArr[height]++;
}
for
(
int
j=
0
; j<=dumpCount; j++) {
// 최대값 스캔
for
(
int
k=
100
; k>=
0
; k--) {
if
(countArr[k] !=
0
) {
max = k;
break
;
}
}
// 최소값 스캔
for
(
int
k=
0
; k<=
100
; k++) {
if
(countArr[k] !=
0
) {
min = k;
break
;
}
}
if
(j!=dumpCount) {
// 블록옴기기 ( 0 ~ dumpCount-1 까지)
countArr[max]--;
countArr[max-
1
]++;
countArr[min]--;
countArr[min+
1
]++;
}
}
// 높이차 출력
System.out.println(String.format(
"#%d %d"
, T, max-min) );
}
}
}
'Knowledge > 알고리즘' 카테고리의 다른 글
1218. [S/W 문제해결 기본] 4일차 - 괄호 짝짓기 (0) | 2017.09.30 |
---|---|
1216. [S/W 문제해결 기본] 3일차 - 회문2 (0) | 2017.09.30 |
1226. [S/W 문제해결 기본] 7일차 - 미로1 (0) | 2017.09.30 |
1206. [S/W 문제해결 기본] 1일차 - View (0) | 2017.09.30 |
백준 1024번 수열의 합 (0) | 2017.08.26 |