結果

問題 No.198 キャンディー・ボックス2
ユーザー FromBooskaFromBooska
提出日時 2023-04-21 11:42:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 876 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 52,736 KB
最終ジャッジ日時 2024-04-24 01:20:37
合計ジャッジ時間 2,416 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 37 ms
52,352 KB
testcase_03 AC 39 ms
52,736 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 36 ms
52,352 KB
testcase_07 AC 38 ms
52,352 KB
testcase_08 AC 37 ms
51,968 KB
testcase_09 AC 42 ms
52,480 KB
testcase_10 AC 39 ms
51,968 KB
testcase_11 AC 39 ms
52,352 KB
testcase_12 AC 40 ms
51,840 KB
testcase_13 AC 39 ms
51,840 KB
testcase_14 AC 40 ms
51,840 KB
testcase_15 AC 40 ms
52,224 KB
testcase_16 AC 38 ms
52,096 KB
testcase_17 AC 39 ms
52,480 KB
testcase_18 AC 38 ms
52,096 KB
testcase_19 WA -
testcase_20 AC 41 ms
52,480 KB
testcase_21 WA -
testcase_22 AC 40 ms
52,096 KB
testcase_23 WA -
testcase_24 AC 36 ms
52,352 KB
testcase_25 WA -
testcase_26 AC 37 ms
52,352 KB
testcase_27 AC 38 ms
52,608 KB
testcase_28 WA -
testcase_29 AC 38 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# medianにすればいいか

B = int(input())
N = int(input())
C = []
for i in range(N):
    C.append(int(input()))
C.sort()

C_cumu = [0]
temp = 0
for i in range(N):
    temp += C[i]
    C_cumu.append(temp)
    
from math import floor, ceil
if N%2 == 1:
    median = C[N//2]
    ans = 0
    ans += median*(N//2) - C_cumu[N//2]
    ans += C_cumu[N] - C_cumu[N//2+1] - median*(N//2)
    #print(median, ans)
else:
    median_low = floor((C[N//2-1]+C[N//2])/2)
    ans_low = 0
    ans_low += median_low*(N//2) - C_cumu[N//2]
    ans_low += C_cumu[N] - C_cumu[N//2] - median_low*(N//2)
    #print(median_low, ans_low)
    median_high = ceil((C[N//2-1]+C[N//2])/2)
    ans_high = 0
    ans_high += median_high*(N//2) -C_cumu[N//2]
    ans_high += C_cumu[N] - C_cumu[N//2] - median_high*(N//2)
    #print(median_high, ans_high)
    ans = min(ans_low, ans_high)
print(ans)








0