PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000204. Tổng đoạn lớn nhất dài ít nhất L (Maximum Subarray Sum with Minimum Length)
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ổng đoạn lớn nhất dài ít nhất L (Maximum Subarray Sum with Minimum Length)
Maximum Subarray Sum with Minimum Length
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers and an integer , find the maximum sum of a consecutive interval of length at least . Negative elements are allowed; the interval must be nonempty.
Input
The first line contains . The second line contains exactly integers .
Output
Print the maximum sum.
Subtasks
- Subtask 1 (30 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (40 points): ; ; .
Example 1
Input
4 2
2 -3 5 -1
Output
4
Explanation
Intervals [3,4] and [1,3] both sum to 4. No other qualifying interval has a larger sum.
Example 2
Input
3 2
-5 -2 -3
Output
-5
Explanation
Interval [2,3] sums to -5; the other qualifying sums are -7 and -10.