結果
問題 |
No.198 キャンディー・ボックス2
|
ユーザー |
![]() |
提出日時 | 2015-10-20 01:20:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 1,000 ms |
コード長 | 469 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-16 09:41:40 |
合計ジャッジ時間 | 1,849 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import math B = int(input()) N = int(input()) C = [int(input()) for i in range(N)] sum_c = sum(C) if N == 1: print(0) exit() l = 0 r = (sum_c + B) // N + 1 total_l = 0 total_r = 0 for i in range(52): ml = (l * 2 + r) // 3 mr = (l + r * 2) // 3 total_l = 0 total_r = 0 for c in C: total_l += abs(ml - c) total_r += abs(mr - c) if total_r >= total_l: r = mr else: l = ml print(min(total_l, total_r))