#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) template class BIT { public: int bits[1< 0) { ret += bits[i]; i -= i & -i; } return ret; } int total() { return sum((1< bt; int N,K,W; signed main() { cin>>N>>K; REP(i,N) { cin >> W; int j = abs(W); if (W > 0) { if (bt.total() - bt.sum(j-1) < K) { bt.add(j,1); } } else { // あれば下ろせる if (bt.bits[j] > 0) { bt.add(j,-1); } } } cout << bt.total() << endl; return 0; }