結果

問題 No.370 道路の掃除
ユーザー lloyzlloyz
提出日時 2023-02-08 00:13:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 428 bytes
コンパイル時間 2,885 ms
コンパイル使用メモリ 86,312 KB
実行使用メモリ 75,360 KB
最終ジャッジ日時 2023-09-19 04:58:38
合計ジャッジ時間 5,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 75 ms
70,728 KB
testcase_02 AC 75 ms
71,020 KB
testcase_03 AC 74 ms
70,996 KB
testcase_04 AC 75 ms
70,756 KB
testcase_05 WA -
testcase_06 AC 75 ms
71,064 KB
testcase_07 AC 75 ms
71,124 KB
testcase_08 AC 75 ms
70,996 KB
testcase_09 WA -
testcase_10 AC 76 ms
71,024 KB
testcase_11 AC 73 ms
71,028 KB
testcase_12 AC 78 ms
71,100 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 78 ms
71,048 KB
testcase_26 WA -
testcase_27 AC 77 ms
70,896 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
D = [int(input()) for _ in range(m)]

D.sort()
ans = 10**18
res = 0
for i in range(m):
    res += abs(D[i])
    if i >= n - 1:
        if D[i - n + 1] <= 0 and D[i] >= 0:
            ans = min(ans, res + min(abs(D[i - n + 1]), D[i]))
        elif D[i] <= 0:
            ans = min(ans, abs(D[i - n + 1]))
        else:
            ans = min(ans, D[i])
        res -= abs(D[i - n + 1])
print(ans)
0