๋ฌธ์
ํ์ด
์๊พธ ํ์ด๋ ํ๊ณ ์ด์ํ ๊ณณ์์ ์ค๋ฅ๋ฅผ ๋ฒํ๋ค. ๋ค๋ฅธ ์ฌ๋์ ์ฝ๋๋ฅผ ํ์ธํด๋ด๋ ํ๋ฆฐ ๊ฒ์ด ์์๋๋ฐ ํ ์คํธ ์ผ์ด์ค๋ฅผ ํ์ธํ๋๋ผ T๋ฅผ 1๋ก ์ง์ ํด ๋์๋ค. ์ฒ์ ํธ๋ ์ฌ์ดํธ๋ค ๋ณด๋ ๋๋ฌด ํท๊ฐ๋ฆฌ๊ณ ์ธ๋ฐ์๋ ๊ณณ์ ์๊ฐ์ ๋ญ๋นํ๊ฒ ๋๋ค..
D3 ๋ฌธ์ ๋ฅผ ๋ช๊ฐ ํ์ด๋ณด๋ ๋์ด๋๊ฐ ํ ๋ฐฑ์ค ์ค๋ฒ3-4์ฏค ๋๋ ๊ฒ ๊ฐ๋ค. ๋ง ์ด๋ ค์ด ๋ฌธ์ ๋ ์์ง ์ํ์ด๋ณด๊ธดํ์ง๋ง D4 ๊น์ง๋ ๋ฌด๋ํ๊ฒ ๊ฐ ์ ์์ ๊ฒ ๊ฐ๋ค.
T = 10
for test_case in range(1, T+1):
dump = int(input())
box = list(map(int, input().split()))
for j in range(dump):
high = max(box)
low = min(box)
high_index = box.index(max(box))
low_index = box.index(min(box))
box[high_index] -= 1
box[low_index] += 1
result = max(box) - min(box)
print("#{} {}".format(test_case, result))
๊ฐ์ฅ ๋์ ๋ฐ์ค๋ฅผ ๊ฐ์ฅ ๋ฎ์ ๊ณณ์ผ๋ก ์ฎ๊ธฐ๋ ๊ฒ์ด๋ค. ๊ฐ์ฅ ๋์ ๋ฐ์ค์ ์ธ๋ฑ์ค์ ๋์ด๋ฅผ ์ฐพ๊ณ ๋ฎ์ ๋ฐ์ค๋ก ์ฎ๊ฒจ์ฃผ๊ธฐ๋ง ํ๋ฉด ๋๋ค. ์ค๊ฐ์ 0์ด ๋์ค๋๋ผ๋ ๊ฐ์ ๋์ผํ๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก break๋ฅผ ๊ฑธ์ง ์์๋ค.
Java ์ฝ๋
package SWEA;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class swea_1208 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int t=1; t<=10; t++){
int dump = Integer.parseInt(br.readLine());
int[] arr = new int[100];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<100; i++){
arr[i] = Integer.parseInt(st.nextToken());
}
for(int i=0; i<dump; i++){
Arrays.sort(arr);
arr[0]++;
arr[99]--;
}
Arrays.sort(arr);
int result = arr[99] - arr[0];
System.out.println("#" + t + " " + result);
}
}
}
'๐๏ธ Algorithm > โน๏ธ SW Expert Academy [SWEA]' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โน๏ธ[SW Expert Academy] [Python] [D3] [1244] ์ต๋ ์๊ธ (1) | 2024.03.18 |
---|---|
โน๏ธ[SW Expert Academy] [Python] [D4] [1210] Ladder1 (0) | 2024.03.15 |
โน๏ธ[SW Expert Academy] [Python] [D4] [1249] ๋ณด๊ธ๋ก (0) | 2024.03.14 |
โน๏ธ[SW Expert Academy] [Python] [D2] [1859] ๋ฐฑ๋ง ์ฅ์ ํ๋ก์ ํธ (0) | 2024.03.13 |
โน๏ธ [SW Expert Academy] [Python] [D3] 1206. View (0) | 2024.03.12 |