PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000199. Ít nhất K phần tử tốt (At Least K Good Elements)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ít nhất K phần tử tốt (At Least K Good Elements)

At Least K Good Elements

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a binary array and a positive integer KK, find the minimum length of a nonempty consecutive interval containing at least KK ones. Print -1 if none exists.

Input

The first line contains n,Kn,K. The second line contains exactly nn integers aia_i.

Output

Print the minimum length, or -1 if no interval qualifies.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; ai∈{0,1}a_i\in\{0,1\}; 1≤K≤n1\le K\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; ai∈{0,1}a_i\in\{0,1\}; 1≤K≤n1\le K\le n; K=1K=1.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; ai∈{0,1}a_i\in\{0,1\}; 1≤K≤n1\le K\le n.

Example 1

Input

6 2
0 1 0 1 1 0

Output

2

Explanation

Interval [4,5] contains two ones. No singleton contains two ones.

Example 2

Input

3 2
0 0 1

Output

-1

Explanation

The entire array contains only one one.