結果

問題 No.198 キャンディー・ボックス2
ユーザー rocoderrocoder
提出日時 2017-08-08 10:21:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2024-04-20 05:08:41
合計ジャッジ時間 2,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
17,696 KB
testcase_01 AC 27 ms
10,752 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 #

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