結果

問題 No.198 キャンディー・ボックス2
ユーザー mokomoko
提出日時 2018-03-17 11:06:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 492 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 7,940 KB
最終ジャッジ日時 2023-08-25 11:49:13
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 15 ms
7,772 KB
testcase_03 AC 15 ms
7,852 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 15 ms
7,804 KB
testcase_09 AC 15 ms
7,724 KB
testcase_10 AC 15 ms
7,744 KB
testcase_11 AC 15 ms
7,820 KB
testcase_12 AC 15 ms
7,808 KB
testcase_13 WA -
testcase_14 AC 15 ms
7,856 KB
testcase_15 AC 15 ms
7,768 KB
testcase_16 AC 15 ms
7,896 KB
testcase_17 AC 15 ms
7,928 KB
testcase_18 AC 15 ms
7,896 KB
testcase_19 AC 14 ms
7,920 KB
testcase_20 AC 14 ms
7,784 KB
testcase_21 AC 15 ms
7,788 KB
testcase_22 AC 15 ms
7,864 KB
testcase_23 WA -
testcase_24 AC 16 ms
7,720 KB
testcase_25 AC 16 ms
7,856 KB
testcase_26 AC 15 ms
7,896 KB
testcase_27 AC 16 ms
7,836 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc(num,c):
	res=0
	for i in c:
		res+=abs(num-i)
	return res

def main():
	b=int(input())
	n=int(input())
	c=list()
	for i in range(n):
		c.append(int(input()))

	c.sort(reverse=True)
	ub=int((sum(c)+b)//n)
	lb=0

	while True:
		left=int((lb*2+ub)/3)
		right=int((lb+ub*2)/3)
		if abs(right-left)<=1:
			break
		if calc(left,c)>calc(right,c):
			lb=left
		else:
			ub=right

	ans=int(1e9)
	for i in range(lb,ub+1):
		ans=min(ans,calc(i,c))
	print(ans)

if __name__=="__main__":
	main()
0