結果

問題 No.370 道路の掃除
ユーザー TatsunoTatsuno
提出日時 2016-05-13 22:54:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 958 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-20 02:58:41
合計ジャッジ時間 2,817 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 35 ms
11,008 KB
testcase_02 AC 35 ms
11,008 KB
testcase_03 AC 35 ms
11,008 KB
testcase_04 AC 35 ms
11,008 KB
testcase_05 AC 34 ms
11,008 KB
testcase_06 AC 35 ms
11,008 KB
testcase_07 AC 35 ms
11,008 KB
testcase_08 AC 35 ms
11,008 KB
testcase_09 AC 35 ms
11,008 KB
testcase_10 AC 35 ms
11,008 KB
testcase_11 AC 36 ms
11,008 KB
testcase_12 AC 36 ms
11,008 KB
testcase_13 AC 31 ms
11,008 KB
testcase_14 AC 30 ms
11,008 KB
testcase_15 AC 35 ms
11,008 KB
testcase_16 AC 35 ms
11,008 KB
testcase_17 AC 31 ms
11,008 KB
testcase_18 AC 35 ms
11,008 KB
testcase_19 AC 35 ms
11,008 KB
testcase_20 AC 38 ms
11,008 KB
testcase_21 AC 37 ms
11,008 KB
testcase_22 AC 36 ms
11,008 KB
testcase_23 AC 38 ms
11,008 KB
testcase_24 AC 33 ms
11,008 KB
testcase_25 AC 36 ms
11,008 KB
testcase_26 AC 38 ms
11,008 KB
testcase_27 AC 36 ms
11,008 KB
testcase_28 AC 38 ms
11,008 KB
testcase_29 AC 38 ms
11,008 KB
testcase_30 AC 32 ms
11,008 KB
testcase_31 AC 34 ms
11,136 KB
testcase_32 WA -
testcase_33 AC 37 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
d=[0]*20001
for i in range(m):
    d[int(input())+10000] += 1
left=0
right=0
acc = 0
for i in range(len(d)):
    acc += d[i]
    right = i
    if acc >= n:
        break

def dist(l, r):
    if r <= 10000:
        return 10000 - l
    if l >= 10000:
        return r - 10000
    return r-l + min(10000 - l, r - 10000)

ans = dist(left, right)
while right < 20000:
    if acc >= n:
        acc -= d[left]
        for i in range(left+1, 20001):
            if d[i] > 0:
                left = i
                break
        else:
            break
        if left >= right:
            acc = d[left]
            right = left
        if acc >= n:
            ans = min(ans, dist(left, right))
            continue

    for i in range(right+1, 20001):
        if d[i] > 0:
            right = i
            break
    else:
        break
    acc += d[right]
    if acc >= n:
        ans = min(ans, dist(left, right))
    
print(ans)
0