結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
rocoder
|
| 提出日時 | 2017-08-07 14:33:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 540 bytes |
| コンパイル時間 | 132 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 15,872 KB |
| 最終ジャッジ日時 | 2024-10-11 23:35:44 |
| 合計ジャッジ時間 | 3,030 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 2 WA * 6 TLE * 1 -- * 17 |
ソースコード
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]
S1=S+B
S1//=N
S//=N
mi=0
for i in range(N):
mi+=ab(S-C[i])
i=C[0]
while i<=S1 and i>=C[0]:
M=0
j=0
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)
rocoder