#include #include using namespace std; template class BinaryIndexTree { public: explicit BinaryIndexTree(int size) { size_ = 1; while (size_ < size) { size_ <<= 1; } tree_.resize(size_); } void add(int k, const T& x) { k++; while (k <= size_) { tree_[k - 1] += x; k += k & -k; } } T sum(int k) { k++; T s = 0; while (k > 0) { s += tree_[k - 1]; k -= k & -k; } return s; } private: int size_; vector tree_; }; const int MAXN = 100000; const int MAXW = 1000000; int N, K, W; int picked[MAXW + 1]; int main() { BinaryIndexTree bit(MAXW + 1); int ans = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> W; if (W > 0) { int cnt = bit.sum(MAXW) - bit.sum(W - 1); if (cnt < K) { ans++; bit.add(W, 1); picked[W]++; } } else if (picked[-W] > 0) { ans--; bit.add(-W, -1); picked[-W]--; } } cout << ans << endl; return 0; }