結果
| 問題 | 
                            No.198 キャンディー・ボックス2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-05-24 08:50:52 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 43 ms / 1,000 ms | 
| コード長 | 258 bytes | 
| コンパイル時間 | 341 ms | 
| コンパイル使用メモリ | 82,220 KB | 
| 実行使用メモリ | 54,356 KB | 
| 最終ジャッジ日時 | 2024-12-20 19:15:21 | 
| 合計ジャッジ時間 | 2,606 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 26 | 
ソースコード
B = int(input())
N = int(input())
C = [int(input()) for _ in range(N)]
S = sum(C)
C.sort()
if N == 1:
    print(0)
    exit()
M = (N + 1) // 2
X = C[M - 1]
if S + B < X * N:
    X = (S + B) // N
cnt = 0
for i in range(N):
    cnt += abs(C[i] - X)
print(cnt)