#K91077. Busiest Period of the Day

    ID: 37895 Type: Default 1000ms 256MiB

Busiest Period of the Day

Busiest Period of the Day

You are given a sequence of integers representing the number of hits received at each minute. In a typical day there are 1440 minutes, and each minute has an associated hit count. You are also provided with an integer w (the window size), which specifies the length of a contiguous time interval to consider.

Your task is to determine the starting minute (0-indexed) of the contiguous interval of length w that yields the maximum total number of hits. In the event of a tie, choose the earliest starting minute.

Mathematically, if hits[i] denotes the number of hits at minute i (with 0 ≤ i < N, where usually N = 1440), you must find the smallest index s such that \[ \sum_{i=s}^{s+w-1}hits[i] \ge \sum_{i=k}^{k+w-1}hits[i] \quad \text{for all } k \text{ with } 0 \le k \le N-w \]

inputFormat

The input is read from standard input and consists of two lines. The first line contains two integers, N and w, separated by a space, where N is the total number of minutes (typically 1440) and w is the size of the time window. The second line contains N space-separated integers; the i-th integer represents the hit count for minute i (0-indexed).

outputFormat

Output a single integer to standard output—the starting minute (0-indexed) of the window that has the maximum sum of hits.## sample

24 5
0 2 3 5 0 0 0 2 7 8 0 5 4 3 1 0 6 5 4 0 0 0 0 3
8