#include #include #include using namespace std; template struct BIT { const Abel UNITY_SUM = 0; vector dat; BIT(int n) : dat(n, UNITY_SUM) { } // [0, n) inline void add(int i, Abel x) { while (i < dat.size()) { dat[i] += x; i |= i + 1; } } inline Abel sum(int i) { // [0, i] Abel res = UNITY_SUM; while (i >= 0) { res += dat[i]; i = (i & (i + 1)) - 1; } return res; } inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); } // [a, b) /* debug */ Abel operator[](int i) { return sum(i, i + 1); } void dump() { for (int i = 0; i < dat.size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main() { int n, k; cin >> n >> k; BIT bit(1000001); int cnt = 0; while (n--) { int w; cin >> w; if (w > 0) { if (cnt - bit.sum(w) >= k) continue; cnt++; bit.add(w, 1); } else { w *= -1; if (bit[w] == 0) continue; bit.add(w, -1); cnt--; } } cout << cnt << endl; return 0; }