結果

問題 No.370 道路の掃除
ユーザー rin204
提出日時 2022-01-20 03:16:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 60,672 KB
最終ジャッジ日時 2024-11-23 14:15:04
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
minus = [0]
plus = [0]
for _ in range(m):
    d = int(input())
    if d > 0:
        plus.append(d)
    elif d == 0:
        n -= 1
    else:
        minus.append(-d)
if n <= 0:
    print(0)
    exit()
    
plus.sort()
minus.sort()
ans = 1 << 30
for i in range(n + 1):
    j = n - i
    if len(plus) <= i or len(minus) <= j:
        continue
    ans = min(ans, plus[i] + minus[j] + min(plus[i], minus[j]))
print(ans)
0