problems / 106

Busiest Five Minutes

easy sliding-window arrays prefix-sums 2000 ms · 256 MB

Busiest Five Minutes

A web server's access log has been boiled down to one number per second: how many requests arrived during that second. The infrastructure team is capacity planning and wants to know the worst k-second window — the stretch of k consecutive seconds that received the most requests in total, since that's the load their servers need to be provisioned for.

You are given the per-second request counts for n consecutive seconds, numbered 1 to n in the order they occurred. Find a window of exactly k consecutive seconds (seconds s, s+1, ..., s+k-1 for some valid starting second s) whose total request count is as large as possible. If several windows tie for the largest total, report the one with the smallest starting second s.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^6).

The second line contains n integers c_1, c_2, ..., c_n (0 ≤ c_i ≤ 10^5), where c_i is the number of requests received during second i.

Output

Print two integers: the total number of requests in the busiest k-second window, and the starting second s (1 ≤ s ≤ n - k + 1) of the earliest window achieving that total.

Notes

The total can exceed what fits in a 32-bit integer, so accumulate it with a 64-bit (or wider) type.

Example 1

Input

10 3
2 1 5 1 3 2 7 1 4 0

Output

12 5

Example 2

Input

5 1
3 5 5 2 1

Output

5 2

Hints · reveal one at a time if you're stuck

Hint 1

Compute the first window's total directly, then ask how that total changes when the window moves one second to the right. What is gained and what is lost?

Hint 2

Each move takes constant time, so one linear pass finds every window total. Keep the best total and its start, updating only on a strictly larger total, and use 64-bit sums since totals can reach about 10^11.

report an issue Prefer your own editor? sooks prep 106 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.