結果

問題 No.370 道路の掃除
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-03 21:42:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 86,636 KB
実行使用メモリ 75,428 KB
最終ジャッジ日時 2023-10-14 21:10:09
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
70,856 KB
testcase_01 AC 78 ms
71,256 KB
testcase_02 AC 76 ms
71,116 KB
testcase_03 AC 78 ms
71,412 KB
testcase_04 AC 77 ms
71,356 KB
testcase_05 AC 77 ms
71,168 KB
testcase_06 AC 77 ms
71,420 KB
testcase_07 AC 77 ms
71,308 KB
testcase_08 AC 77 ms
71,260 KB
testcase_09 AC 78 ms
71,112 KB
testcase_10 AC 78 ms
71,184 KB
testcase_11 AC 78 ms
71,356 KB
testcase_12 AC 80 ms
71,260 KB
testcase_13 AC 79 ms
71,160 KB
testcase_14 AC 80 ms
71,176 KB
testcase_15 AC 80 ms
71,200 KB
testcase_16 AC 80 ms
71,428 KB
testcase_17 AC 79 ms
71,288 KB
testcase_18 AC 80 ms
71,076 KB
testcase_19 AC 79 ms
71,168 KB
testcase_20 AC 87 ms
71,124 KB
testcase_21 AC 86 ms
71,220 KB
testcase_22 AC 84 ms
71,160 KB
testcase_23 AC 86 ms
71,176 KB
testcase_24 AC 81 ms
71,168 KB
testcase_25 AC 83 ms
71,344 KB
testcase_26 AC 91 ms
75,032 KB
testcase_27 AC 83 ms
71,228 KB
testcase_28 AC 85 ms
71,260 KB
testcase_29 AC 88 ms
71,068 KB
testcase_30 AC 94 ms
75,428 KB
testcase_31 AC 85 ms
71,120 KB
testcase_32 AC 87 ms
71,260 KB
testcase_33 AC 91 ms
75,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
D = [int(input()) for i in range(m)]
N = []
P = []
for d in D:
    if d < 0:
        N.append(abs(d))
    else:
        P.append(d)
P.sort()
N.sort()

ans = 10**18
for i in range(0, len(P)+1):
    if i > n:
        continue
    j = n-i
    if j > len(N):
        continue
    if i == 0:
        temp = N[j-1]
    elif j == 0:
        temp = P[i-1]
    else:
        temp = min(2*P[i-1]+N[j-1], P[i-1]+2*N[j-1])
    ans = min(ans, temp)
print(ans)
0