An exchange rate is logged as a positive integer on each of n consecutive days. Over every block of exactly k consecutive days, consider the average rate. Report the maximum such average as a fraction in lowest terms.
Because the window width k is fixed, the average equals the window sum divided by k. Output the maximum sum divided by k, reduced to lowest terms, written as p/q (with q >= 1 and gcd(p, q) = 1). When the reduced denominator is 1, still print it (for example 5/1).
Line 1: two integers n and k.
Line 2: n space-separated positive integers, the daily rates.
One line: the maximum k-day average as a reduced fraction p/q.
Example 1
Input
5 2 1 3 2 5 4
Expected
9/2
Explanation
The 2-day sums are 4, 5, 7, 9; the largest is 9, so the best average is 9/2, already in lowest terms.
Example 2
Input
4 4 2 4 6 8
Expected
5/1
Explanation
One window sums to 20, and 20/4 reduces to 5/1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →