using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int N, K; private int[] W; private void Scan() { var line = Console.ReadLine().Split(' '); N = int.Parse(line[0]); K = int.Parse(line[1]); W = new int[N]; for (int i = 0; i < N; i++) { W[i] = int.Parse(Console.ReadLine()); } } public void Solve() { Scan(); var segtree = new SegmentTree(100001); foreach (int i in W) { if (i > 0) { if (segtree.Query(i, 100001) < K) { segtree.Update(i, segtree.Tree[i] + 1); } } else { int j = -i; segtree.Update(j, Math.Max(0, segtree.Tree[j] - 1)); } } Console.WriteLine(segtree.Tree[0]); } } class SegmentTree { private int N; public int[] Tree; public SegmentTree(int length) { for (N = 1; N <= length; N *= 2) ; Tree = (new int[2 * N - 1]); } /// /// index(0_indexed)をvに更新 /// /// /// public void Update(int index, int v) { int i = index + N - 1; Tree[i] = v; while (i > 0) { i = (i - 1) / 2; Tree[i] = Tree[i * 2 + 1] + Tree[i * 2 + 2]; } } public int Query(int left, int right) { return Query(left, right, 0, 0, N); } private int Query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) { return Tree[k]; } else { int vl = Query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = Query(a, b, k * 2 + 2, (l + r) / 2, r); return vl + vr; ; } } }