結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2015-10-20 00:56:46 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 55 ms / 1,000 ms |
コード長 | 544 bytes |
コンパイル時間 | 206 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-16 09:41:24 |
合計ジャッジ時間 | 2,302 ms |
ジャッジサーバーID (参考情報) |
judge5 / 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(int(math.log(sum_c + B, 3)*200) + 2): 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(l, ml, total_l, mr, total_r, r) print(min(total_l, total_r))