結果

問題 No.198 キャンディー・ボックス2
ユーザー taba
提出日時 2016-04-16 21:17:43
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 343 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-04 10:20:12
合計ジャッジ時間 1,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 6 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

b=input()
n=input()
c=sorted([input()for i in[0]*n])
a=0
while len(set(c))>2:
	c=sorted(c)
	a+=c[-1]-c[-2]
	b+=c[-1]-c[-2]
	c[-1]-=c[-2]
	if c[1]-c[0]<=b:
		a+=c[1]-c[0]
		b-=c[1]-c[0]
		c[0]+=c[1]-c[0]
#print c
#print b,a
if len(set(c))==2:
	l=c.count(min(c))
	h=c.count(max(c))
	if l<=b and l<h:
		print a+l
	else:
		print a+h
else:
	print a
0