結果

問題 No.59 鉄道の旅
ユーザー tnodinotnodino
提出日時 2022-02-26 20:27:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 587 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 10,744 KB
実行使用メモリ 16,308 KB
最終ジャッジ日時 2023-09-17 23:45:05
合計ジャッジ時間 3,903 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
16,308 KB
testcase_01 AC 34 ms
16,180 KB
testcase_02 AC 34 ms
16,296 KB
testcase_03 AC 34 ms
16,260 KB
testcase_04 AC 557 ms
16,216 KB
testcase_05 AC 34 ms
16,208 KB
testcase_06 AC 34 ms
16,144 KB
testcase_07 AC 34 ms
16,184 KB
testcase_08 AC 93 ms
16,240 KB
testcase_09 AC 91 ms
16,256 KB
testcase_10 AC 93 ms
16,240 KB
testcase_11 AC 68 ms
16,144 KB
testcase_12 AC 325 ms
16,260 KB
testcase_13 AC 583 ms
16,260 KB
testcase_14 AC 587 ms
16,292 KB
testcase_15 AC 34 ms
16,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
class BinaryIndexedTree:
    def __init__(self, N):
        self.sz = N
        self.bit = [0] * (N + 1)

    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def Add(self, i, x):
        while i <= self.sz:
            self.bit[i] += x
            i += i & -i

INF = 10**6
N,K = map(int,input().split())
BIT = BinaryIndexedTree(INF)
for _ in range(N):
    W = int(input())
    if W < 0:
        W = abs(W)
        if BIT.Sum(W) - BIT.Sum(W-1) > 0:
            BIT.Add(W, -1)
    else:
        if BIT.Sum(INF) - BIT.Sum(W-1) < K:
            BIT.Add(W, 1)
print(BIT.Sum(INF))
0