結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー | あかりき |
提出日時 | 2021-03-15 00:07:12 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 207 ms / 1,000 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 269 ms |
コンパイル使用メモリ | 87,040 KB |
実行使用メモリ | 98,992 KB |
最終ジャッジ日時 | 2023-08-06 09:16:43 |
合計ジャッジ時間 | 6,607 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 207 ms
86,520 KB |
testcase_01 | AC | 205 ms
86,452 KB |
testcase_02 | AC | 193 ms
98,768 KB |
testcase_03 | AC | 178 ms
94,628 KB |
testcase_04 | AC | 191 ms
98,468 KB |
testcase_05 | AC | 201 ms
98,920 KB |
testcase_06 | AC | 191 ms
98,800 KB |
testcase_07 | AC | 181 ms
94,872 KB |
testcase_08 | AC | 196 ms
98,660 KB |
testcase_09 | AC | 97 ms
76,816 KB |
testcase_10 | AC | 96 ms
77,060 KB |
testcase_11 | AC | 115 ms
76,800 KB |
testcase_12 | AC | 138 ms
98,992 KB |
testcase_13 | AC | 205 ms
98,752 KB |
testcase_14 | AC | 89 ms
76,160 KB |
testcase_15 | AC | 89 ms
75,968 KB |
testcase_16 | AC | 101 ms
77,248 KB |
testcase_17 | AC | 97 ms
77,036 KB |
testcase_18 | AC | 115 ms
77,048 KB |
testcase_19 | AC | 148 ms
78,700 KB |
testcase_20 | AC | 180 ms
86,776 KB |
testcase_21 | AC | 188 ms
86,836 KB |
testcase_22 | AC | 194 ms
86,760 KB |
testcase_23 | AC | 175 ms
85,480 KB |
testcase_24 | AC | 169 ms
88,432 KB |
testcase_25 | AC | 192 ms
80,540 KB |
testcase_26 | AC | 202 ms
86,152 KB |
testcase_27 | AC | 202 ms
98,528 KB |
testcase_28 | AC | 184 ms
81,236 KB |
testcase_29 | AC | 204 ms
86,600 KB |
ソースコード
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) x=sum(c)+b t3=x//n for i in range(max(t3-10**5,0),t3+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))