Codeforces Round 387 (Div. 2)
D
Winter Is Coming
Codeforces
1800
原题
← CE →
翻译中…

The winter in Berland lasts $*n*$ days. For each day we know the forecast for the average air temperature that day.

翻译中…

Vasya has a new set of winter tires which allows him to drive safely no more than $*k*$ days at any average air temperature. After $*k*$ days of using it (regardless of the temperature of these days) the set of winter tires wears down and cannot be used more. It is not necessary that these $*k*$ days form a continuous segment of days.

翻译中…

Before the first winter day Vasya still uses summer tires. It is possible to drive safely on summer tires any number of days when the average air temperature is non-negative. It is impossible to drive on summer tires at days when the average air temperature is negative.

翻译中…

Vasya can change summer tires to winter tires and vice versa at the beginning of any day.

翻译中…

Find the minimum number of times Vasya needs to change summer tires to winter tires and vice versa to drive safely during the winter. At the end of the winter the car can be with any set of tires.

翻译中…

Input

翻译中…

The first line contains two positive integers $*n*$ and $*k*$ ($1 ≤ *n* ≤ 2·10^{5}$, $0 ≤ *k* ≤ *n*$) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than $*k*$ days in total.

翻译中…

The second line contains a sequence of $*n*$ integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($- 20 ≤ *t*_{*i*} ≤ 20$) — the average air temperature in the $*i*$-th winter day.

翻译中…

Output

翻译中…

Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.

翻译中…

Note

翻译中…

In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two.

翻译中…

In the second example before the first winter day Vasya should change summer tires to winter tires, and then after the first winter day change winter tires to summer tires. After the second day it is necessary to change summer tires to winter tires again, and after the third day it is necessary to change winter tires to summer tires. Thus, the total number of tires' changes equals four.

翻译中…

样例

Input #1
4 3
-5 20 -3 0
Output #1
2
InputCopy OutputCopy
Input #2
4 2
-5 20 -3 0
Output #2
4
InputCopy OutputCopy
Input #3
10 6
2 -5 1 3 0 0 -4 -3 1 0
Output #3
3
InputCopy OutputCopy
题目信息
题号
747D
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。