結果

問題 No.198 キャンディー・ボックス2
ユーザー rocoderrocoder
提出日時 2017-08-07 14:33:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 12,692 KB
最終ジャッジ日時 2023-08-02 04:32:09
合計ジャッジ時間 2,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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)
0