#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(int *x, int *y){reader(x);reader(y);} void reader(int *x, int *y, int *z){reader(x);reader(y);reader(z);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} template struct fenwick{ int size, memory; T *data; void malloc(int mem){ memory = mem; data = (T*)std::malloc(sizeof(T)*mem); } void *malloc(int mem, void *workMemory){ memory = mem; data = (T*)workMemory; return (void*)(data + mem); } void free(void){ memory = 0; free(data); } void init(int N){ int i; size = N; rep(i,N) data[i] = 0; } void add(int k, T val){ while(k < size) data[k] += val, k |= k+1; } T get(int k){ T res = 0; while(k>=0) res += data[k], k = (k&(k+1))-1; return res; } T range(int a, int b){ return get(b) - get(a-1); } int kth(T k){ int i=0, j=size, c; T v; while(i t; t.malloc(1100000); t.init(1100000); reader(&N,&K); while(N--){ reader(&W); if(W>0){ W = 1000000-W; if(t.kth(K-1) != -1 && t.kth(K-1) <= W) continue; // too slow binary search // if(t.get(W) >= K) continue; t.add(W,1); arr[W]++; } else { W = 1000000+W; if(arr[W]) t.add(W,-1), arr[W]--; } } writer(t.get(1000001),'\n'); return 0; }