package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func Scan() (input string) { scanner := bufio.NewScanner(os.Stdin) if scanner.Scan() { input = scanner.Text() } return } func Sign(n int) (int, string) { if n >= 0 { return n, "+" } else { ns := []byte(strconv.Itoa(n)) n, _ := strconv.Atoi(string(ns[1:])) return n, "-" } } func Sum(xs ...int) (s int) { for _, x := range xs { s += x } return } func main() { list := make([]int, 1000001) NK := strings.Split(Scan(), " ") N, _ := strconv.Atoi(NK[0]) K, _ := strconv.Atoi(NK[1]) for i := 0; i < N; i++ { W, _ := strconv.Atoi(Scan()) W, s := Sign(W) if s == "+" { if Sum(list[W:]...) < K { list[W] += 1 } } else if s == "-" { if list[W] > 0 { list[W] -= 1 } } } fmt.Println(Sum(list...)) }