結果

問題 No.370 道路の掃除
ユーザー kjnho
提出日時 2016-05-13 23:06:49
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-10-05 17:31:20
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8

from collections import defaultdict as dd
from collections import Counter
from collections import deque
from string import ascii_lowercase

def main():
    N,M = map(int,raw_input().split())
    Dp = []
    Dn = []
    for m in range(M):
        p = input()
        if p == 0:
            N = N-1
        elif p > 0:
            Dp.append(p)
        else:
            Dn.append(-p)
    Dp.sort()
    Dn.sort()

    distances = []
    for n in range(N+1): # n is negative number
        if N-n <= len(Dp):
            a = Dp[N-n-1]
            if N-n == N:
                distances.append(a)
                continue
        else:
            continue
        if  n <= len(Dn):
            b = Dn[n-1]
            if n == N:
                distances.append(b)
                continue
        else:
            continue
        distances.append(2*a + b if a < b else a + 2*b)

    distances.sort()
    print(distances[0])


if __name__ == "__main__":
    main()
0