結果

問題 No.59 鉄道の旅
ユーザー tnodinotnodino
提出日時 2022-02-26 20:17:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 668 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 16,088 KB
最終ジャッジ日時 2023-09-17 23:22:42
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
16,040 KB
testcase_01 AC 31 ms
15,912 KB
testcase_02 AC 31 ms
16,012 KB
testcase_03 AC 32 ms
16,036 KB
testcase_04 AC 563 ms
15,836 KB
testcase_05 WA -
testcase_06 AC 32 ms
16,040 KB
testcase_07 WA -
testcase_08 AC 91 ms
15,824 KB
testcase_09 AC 88 ms
16,064 KB
testcase_10 WA -
testcase_11 AC 65 ms
16,024 KB
testcase_12 AC 331 ms
16,060 KB
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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):
        i += 1
        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+1) - BIT.Sum(W) > 0:
            BIT.Add(W, -1)
    else:
        if BIT.Sum(INF) - BIT.Sum(W) < K:
            BIT.Add(W, 1)
print(BIT.Sum(INF))
0