結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2017-08-08 10:21:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 633 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 17,444 KB |
最終ジャッジ日時 | 2024-10-12 00:08:46 |
合計ジャッジ時間 | 3,036 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | AC * 2 WA * 6 TLE * 1 -- * 17 |
ソースコード
# your code goes here def ab(num): if num<0: num*=-1 return num B=int(input()) N=int(input()) C=[int(input()) for i in range(N)] C.sort(reverse=True) #print(C) S=0 for i in range(N): S+=C[i] # print(S) S1=S+B #print(S1) S1//=N S//=N mi=0 for i in range(N): mi+=ab(S-C[i]) i=S-3 if i<C[0]: i=C[0] #print(S1) while i<=S1 and i>=C[0]: M=0 j=0 #print(B) while B>0 and j<N: ma=ab(i-C[j]) # print(ma) B-=ma M+=ma j+=1 if B<0: j-=1 M+=B C[j]+=B while j<N: M+=ab(C[j]-i) if M<mi: mi=M i+=1 print(mi)