PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000196. Đoạn dài nhất có trung bình không nhỏ hơn K (Longest Subarray With Mean 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 không nhỏ hơn K (Longest Subarray With Mean At Least K)
Longest Subarray With Mean 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 arithmetic mean is at least , equivalently . Print 0 if no such interval exists.
Input
The first line contains . The second contains exactly integers .
Output
Print the maximum length, or 0 if none exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
5 5
7 2 6 1 8
Output
3
Explanation
Interval [3,5] sums to 15, mean 5. The two length-four sums are 16 and 17; the full sum is 24, so no longer interval qualifies.
Example 2
Input
3 0
-3 -2 -1
Output
0
Explanation
Every interval has negative sum.