結果

問題 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
コンパイル時間 404 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-08-02 02:36:58
合計ジャッジ時間 2,507 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,340 KB
testcase_01 AC 21 ms
8,344 KB
testcase_02 AC 21 ms
8,356 KB
testcase_03 AC 21 ms
8,372 KB
testcase_04 AC 21 ms
8,220 KB
testcase_05 AC 21 ms
8,368 KB
testcase_06 AC 21 ms
8,304 KB
testcase_07 AC 21 ms
8,316 KB
testcase_08 AC 21 ms
8,268 KB
testcase_09 AC 22 ms
8,276 KB
testcase_10 AC 21 ms
8,220 KB
testcase_11 AC 20 ms
8,176 KB
testcase_12 AC 20 ms
8,344 KB
testcase_13 AC 20 ms
8,184 KB
testcase_14 AC 21 ms
8,272 KB
testcase_15 AC 20 ms
8,368 KB
testcase_16 AC 20 ms
8,340 KB
testcase_17 AC 21 ms
8,180 KB
testcase_18 AC 21 ms
8,184 KB
testcase_19 AC 20 ms
8,144 KB
testcase_20 AC 22 ms
8,148 KB
testcase_21 AC 22 ms
8,248 KB
testcase_22 AC 21 ms
8,148 KB
testcase_23 AC 23 ms
8,316 KB
testcase_24 AC 21 ms
8,356 KB
testcase_25 AC 21 ms
8,268 KB
testcase_26 AC 23 ms
8,148 KB
testcase_27 AC 21 ms
8,272 KB
testcase_28 AC 22 ms
8,352 KB
testcase_29 AC 23 ms
8,256 KB
testcase_30 AC 23 ms
8,328 KB
testcase_31 AC 22 ms
8,168 KB
testcase_32 WA -
testcase_33 AC 24 ms
8,364 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