結果

問題 No.198 キャンディー・ボックス2
ユーザー あかりきあかりき
提出日時 2021-03-15 00:00:04
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 375 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 161,492 KB
最終ジャッジ日時 2023-08-06 09:10:20
合計ジャッジ時間 11,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 419 ms
159,080 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 409 ms
159,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 129 ms
76,600 KB
testcase_10 AC 129 ms
76,716 KB
testcase_11 AC 140 ms
76,544 KB
testcase_12 AC 202 ms
161,492 KB
testcase_13 WA -
testcase_14 AC 81 ms
75,924 KB
testcase_15 AC 81 ms
76,168 KB
testcase_16 AC 123 ms
76,680 KB
testcase_17 AC 128 ms
76,904 KB
testcase_18 AC 140 ms
76,856 KB
testcase_19 AC 186 ms
77,084 KB
testcase_20 AC 308 ms
110,684 KB
testcase_21 AC 340 ms
110,164 KB
testcase_22 AC 340 ms
109,820 KB
testcase_23 WA -
testcase_24 AC 239 ms
109,992 KB
testcase_25 RE -
testcase_26 AC 379 ms
109,560 KB
testcase_27 AC 414 ms
159,152 KB
testcase_28 RE -
testcase_29 AC 417 ms
157,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

b=int(input())
n=int(input())
c=[int(input()) for i in range(n)]
c.sort()
if n//2==1:
  t=c[n//2]
else:
  t=(c[n//2-1]+c[n//2])//2
ans=[]
for i in range(max(t-10**6,0),t+10**6):
  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