結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  tnodino | 
| 提出日時 | 2022-02-26 20:17:32 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 668 bytes | 
| コンパイル時間 | 754 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 18,560 KB | 
| 最終ジャッジ日時 | 2024-07-04 16:46:29 | 
| 合計ジャッジ時間 | 4,398 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 6 WA * 4 RE * 2 | 
ソースコード
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))
            
            
            
        