結果

問題 No.198 キャンディー・ボックス2
ユーザー あかりきあかりき
提出日時 2021-03-15 00:02:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 98,772 KB
最終ジャッジ日時 2023-08-06 09:12:09
合計ジャッジ時間 6,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
86,264 KB
testcase_01 AC 162 ms
86,252 KB
testcase_02 AC 157 ms
91,712 KB
testcase_03 AC 152 ms
91,624 KB
testcase_04 AC 157 ms
91,664 KB
testcase_05 AC 164 ms
91,912 KB
testcase_06 AC 158 ms
91,404 KB
testcase_07 AC 150 ms
91,708 KB
testcase_08 AC 162 ms
91,836 KB
testcase_09 AC 85 ms
76,436 KB
testcase_10 AC 84 ms
76,452 KB
testcase_11 AC 103 ms
77,076 KB
testcase_12 AC 125 ms
98,772 KB
testcase_13 AC 164 ms
91,944 KB
testcase_14 AC 85 ms
76,200 KB
testcase_15 AC 83 ms
76,200 KB
testcase_16 AC 87 ms
76,376 KB
testcase_17 AC 83 ms
76,344 KB
testcase_18 AC 106 ms
77,020 KB
testcase_19 AC 125 ms
77,944 KB
testcase_20 AC 145 ms
85,804 KB
testcase_21 AC 152 ms
85,540 KB
testcase_22 AC 156 ms
85,452 KB
testcase_23 WA -
testcase_24 AC 134 ms
86,752 KB
testcase_25 RE -
testcase_26 AC 157 ms
84,460 KB
testcase_27 AC 173 ms
92,592 KB
testcase_28 RE -
testcase_29 AC 161 ms
86,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

b=int(input())
n=int(input())
c=[int(input()) for i in range(n)]
c.sort()
ans=[]
if n//2==1:
  t=c[n//2]
  for i in range(max(t-10**5,0),t+10**5):
    ct=0
    y=b
    for j in range(n):
      if c[j]>=i:
        ct+=c[j]-i
        y+=c[j]-i
    for j in range(n):
      if c[j]<i:
        ct+=i-c[j]
        y-=i-c[j]
    if y>=0:
      ans.append(ct)
else:
  t1=c[n//2-1]
  t2=c[n//2]
  for i in range(max(t1-10**5,0),t1+10**5):
    ct=0
    y=b
    for j in range(n):
      if c[j]>=i:
        ct+=c[j]-i
        y+=c[j]-i
    for j in range(n):
      if c[j]<i:
        ct+=i-c[j]
        y-=i-c[j]
    if y>=0:
      ans.append(ct)
  for i in range(max(t2-10**5,0),t2+10**5):
    ct=0
    y=b
    for j in range(n):
      if c[j]>=i:
        ct+=c[j]-i
        y+=c[j]-i
    for j in range(n):
      if c[j]<i:
        ct+=i-c[j]
        y-=i-c[j]
    if y>=0:
      ans.append(ct)
print(min(ans))
0