結果

問題 No.59 鉄道の旅
ユーザー dangodango
提出日時 2023-07-09 20:46:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 456 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 93,008 KB
最終ジャッジ日時 2023-10-01 00:42:33
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
86,764 KB
testcase_01 AC 74 ms
86,776 KB
testcase_02 AC 75 ms
86,920 KB
testcase_03 AC 78 ms
86,848 KB
testcase_04 AC 169 ms
92,920 KB
testcase_05 AC 78 ms
86,576 KB
testcase_06 AC 80 ms
90,872 KB
testcase_07 AC 76 ms
86,684 KB
testcase_08 AC 114 ms
92,752 KB
testcase_09 AC 114 ms
93,008 KB
testcase_10 AC 115 ms
92,716 KB
testcase_11 AC 107 ms
92,740 KB
testcase_12 AC 142 ms
92,804 KB
testcase_13 AC 160 ms
92,760 KB
testcase_14 AC 171 ms
92,748 KB
testcase_15 AC 76 ms
86,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
M = 10 ** 6 + 1
B = [0] * M
C = [0] * M
def A(a, w):
    while a < M:
        B[a] += w
        a += a & (-a)
def S(a):
    r = 0
    while a > 0:
        r += B[a]
        a -= a & (-a)
    return r
while N:
    N -= 1
    w = int(input())
    if w > 0:
        if S(M - w) < K:
            A(M - w, 1)
            C[w] += 1
    else:
        if C[-w] > 0:
            A(M + w, -1)
            C[-w] -= 1

print(S(M - 1))
0