PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000207. Đoạn dài nhất có trung bình ít nhất K (Longest Subarray with Average at Least K)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đoạn dài nhất có trung bình ít nhất K (Longest Subarray with Average at Least K)
Longest Subarray with Average at Least K
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers and an integer , find the maximum length of a nonempty consecutive interval whose average is at least . Print 0 if no such interval exists.
Input
The first line contains . The second line contains exactly integers .
Output
Print the maximum length, or 0 if none exists.
Subtasks
- Subtask 1 (30 points): ; ; .
- Subtask 2 (30 points): ; ; ; for all .
- Subtask 3 (40 points): ; ; .
Example 1
Input
3 2
1 3 2
Output
3
Explanation
The full array has average 2 and maximum possible length 3.
Example 2
Input
3 0
-5 -2 -3
Output
0
Explanation
All elements are negative, so every interval has average below zero.