結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2020-05-23 19:42:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 29 ms / 1,000 ms |
コード長 | 340 bytes |
コンパイル時間 | 101 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-10-08 21:18:24 |
合計ジャッジ時間 | 1,806 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import sys input=lambda: sys.stdin.readline().rstrip() b=int(input()) n=int(input()) C=[int(input()) for _ in range(n)] l=0 r=(b+sum(C))//n def ct(x): ret=0 for c in C: ret+=abs(c-x) return ret while r-l>2: mid1,mid2=l+(r-l)//3,r-(r-l)//3 if ct(mid1)<ct(mid2): r=mid2 else: l=mid1 print(min(ct(l),ct(l+1),ct(r)))