#BS0000400. Đoạn con có trung bình lớn nhất (Maximum Average Segment)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đoạn con có trung bình lớn nhất (Maximum Average Segment)
Maximum Average Segment
Version: Phuoc Hung OJ Extended
PHOJ practice edition. Its constraints, input/output format, examples and judging rules are specified below.
Problem Statement
Given an integer array of length and an integer , select a contiguous segment from index to of length at least with maximum arithmetic mean. Any optimal segment is accepted.
Input
The first line contains . The second line contains integers .
Output
Print two integers (1-based) specifying an optimal segment. Its mean must be exactly optimal; no floating-point tolerance is used.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Created examples
Input
6 4
1 12 0 0 50 3
Output
2 5
Explanation
With , the length-4 segments have sums 13, 62 and 53; the largest mean in that group is . The length-5 means are and . The length-6 mean is . Hence indices 2 through 5 are optimal.
Input
4 2
0 0 0 0
Output
1 2
Explanation
All four elements are zero. Every segment of length at least 2 has sum and mean zero. Indices 1 through 2 describe one valid optimal segment.
Input
3 3
100 0 5
Output
1 3
Explanation
Since , only the segment from 1 through 3 is long enough. Its sum is and its mean is . Output indices 1 and 3.