結果
問題 | No.59 鉄道の旅 |
ユーザー | H3PO4 |
提出日時 | 2020-04-22 22:33:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 717 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 18,608 KB |
最終ジャッジ日時 | 2024-10-12 06:58:20 |
合計ジャッジ時間 | 4,451 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, K = map(int, input().split()) MAX = 1000000 B = Bit(MAX) for _ in range(N): W = int(input()) if W > 0: if B.sum(MAX) - B.sum(W - 1) < K: B.add(W, 1) else: if B.sum(-W) - B.sum(-W - 1): B.add(-W, -1) print(B.sum(MAX))