結果

問題 No.370 道路の掃除
ユーザー nebukuro09nebukuro09
提出日時 2016-10-25 11:46:55
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 05:58:27
合計ジャッジ時間 1,604 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 9 ms
6,940 KB
testcase_06 AC 9 ms
6,940 KB
testcase_07 AC 9 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 11 ms
6,940 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 9 ms
6,944 KB
testcase_19 AC 10 ms
6,940 KB
testcase_20 AC 23 ms
6,940 KB
testcase_21 WA -
testcase_22 AC 17 ms
6,944 KB
testcase_23 AC 21 ms
6,944 KB
testcase_24 AC 10 ms
6,944 KB
testcase_25 AC 15 ms
6,944 KB
testcase_26 AC 26 ms
6,940 KB
testcase_27 AC 12 ms
6,944 KB
testcase_28 AC 14 ms
6,940 KB
testcase_29 AC 21 ms
6,940 KB
testcase_30 AC 28 ms
6,940 KB
testcase_31 AC 15 ms
6,940 KB
testcase_32 AC 23 ms
6,940 KB
testcase_33 AC 31 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, raw_input().split())
D = [int(raw_input()) for _ in xrange(M)]
plus = sorted([d for d in D if d > 0])
minus = sorted([abs(d) for d in D if d < 0])
if 0 in D:
    N -= 1

if M == 0:
    print 0
    exit()
if len(plus) == 0:
    print minus[N-1]
    exit()
if len(minus) == 0:
    print plus[N-1]
    exit()

ans = float('inf')
for i in xrange(len(plus)+1):
    for j in xrange(len(minus)+1):
        if i+j == N:
            if i == 0:
                ans = min(ans, minus[j-1])
            elif j == 0:
                ans = min(ans, plus[j-1])
            else:
                a, b = sorted([plus[i-1], minus[j-1]])
                ans = min(ans, a*2+b)
print ans
0