結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  tnodino | 
| 提出日時 | 2022-02-26 20:20:58 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 756 bytes | 
| コンパイル時間 | 394 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 28,980 KB | 
| 最終ジャッジ日時 | 2024-07-04 16:55:24 | 
| 合計ジャッジ時間 | 3,896 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 8 WA * 4 | 
ソースコード
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):
        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)
cnt = defaultdict(int)
for _ in range(N):
    W = int(input())
    if W < 0:
        W = abs(W)
        if cnt[W] > 0:
            BIT.Add(W, -1)
            cnt[W] -= 1
    else:
        if BIT.Sum(INF) - BIT.Sum(W) < K:
            BIT.Add(W, 1)
            cnt[W] += 1
print(BIT.Sum(INF))
            
            
            
        