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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Í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 , find the minimum length of a nonempty consecutive interval containing at least ones. Print -1 if none exists.
Input
The first line contains . The second line contains exactly integers .
Output
Print the minimum length, or -1 if no interval qualifies.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
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.