結果

問題 No.198 キャンディー・ボックス2
ユーザー あかりきあかりき
提出日時 2021-03-15 00:02:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 101,144 KB
最終ジャッジ日時 2024-04-24 05:11:54
合計ジャッジ時間 4,480 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
83,836 KB
testcase_01 AC 125 ms
83,304 KB
testcase_02 AC 132 ms
91,312 KB
testcase_03 AC 117 ms
92,224 KB
testcase_04 AC 123 ms
91,144 KB
testcase_05 AC 135 ms
91,272 KB
testcase_06 AC 127 ms
91,400 KB
testcase_07 AC 120 ms
92,100 KB
testcase_08 AC 138 ms
90,888 KB
testcase_09 AC 59 ms
69,880 KB
testcase_10 AC 56 ms
69,444 KB
testcase_11 AC 76 ms
75,916 KB
testcase_12 AC 94 ms
101,144 KB
testcase_13 AC 131 ms
91,268 KB
testcase_14 AC 53 ms
62,184 KB
testcase_15 AC 51 ms
62,108 KB
testcase_16 AC 56 ms
70,932 KB
testcase_17 AC 56 ms
70,092 KB
testcase_18 AC 75 ms
75,648 KB
testcase_19 AC 94 ms
77,200 KB
testcase_20 AC 117 ms
84,460 KB
testcase_21 AC 121 ms
84,584 KB
testcase_22 AC 127 ms
84,632 KB
testcase_23 WA -
testcase_24 AC 104 ms
84,872 KB
testcase_25 RE -
testcase_26 AC 128 ms
84,344 KB
testcase_27 AC 135 ms
92,236 KB
testcase_28 RE -
testcase_29 AC 124 ms
83,692 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