結果
問題 |
No.59 鉄道の旅
|
ユーザー |
|
提出日時 | 2022-11-07 00:54:03 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 846 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 81,916 KB |
実行使用メモリ | 78,304 KB |
最終ジャッジ日時 | 2024-07-20 11:25:48 |
合計ジャッジ時間 | 1,837 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 RE * 10 |
ソースコード
class FenwickTree: # (BinaryIndexedTree) def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): out = 0 while i > 0: out += self.tree[i] i -= (i & -i) return out def add(self, i, x): while i <= self.size: self.tree[i] += x i += (i & -i) N,K = map(int,input().split()) M = 100001 BIT = FenwickTree(M) for _ in range(N): W = int(input()) if W > 0: # 荷物を積む cnt = BIT.sum(M) - (BIT.sum(W - 1) if W > 1 else 0) # その荷物以上の荷物の重さ if cnt < K: # 積める BIT.add(W, 1) else: # 荷物を下ろす W *= (-1) cnt = BIT.sum(W) - (BIT.sum(W - 1) if W > 1 else 0) if cnt > 0: BIT.add(W, -1) print(BIT.sum(M))