#include #include #include #include #include #include #include #include #include #include #include using namespace std; //RSQ (0-indexed) template struct BIT { vector bit; long long N; T P; BIT (long long n, T p = 0){ N = n; P = p; bit.resize(N); } void add(long long loc, T val){ loc++; while(loc <= N){ bit[loc-1] += val; if (P) bit[loc-1] %= P; loc += loc & -loc; } } long long sum(long long l, long long r){ T res = _sum(r) - _sum(l-1); if (P) res = (res + P) % P; return res; } long long _sum(long long r){ r++; T res = 0; while(r > 0){ res += bit[r-1]; if (P) res %= P; r -= r & -r; } return res; } }; int main(){ long long N, K, W, cnt; cin >> N >> K; BIT tree(1000001); for (int i=0; i> W; if (W > 0){ cnt = tree.sum(W, 1000000); if (cnt < K) tree.add(W, 1); } else{ W *= -1; if (tree.sum(W, W) > 0) tree.add(W, -1); } } cout << tree.sum(0, 1000000) << endl; return 0; }