Mobile coding works. A laptop is faster for long sessions.

Problem

Read two positive natural numbers n and L with L <= n, then n integers forming a sequence v[1], v[2], ..., v[n]. Find the contiguous subarray of exactly L elements whose sum is greatest.

Because dividing by L preserves order, a window of length L with the greatest sum also has the greatest average, so the problem is equivalent to finding the fixed-length window of maximum average.

Print the position of the first element of that window (numbered from 1) and the value of the sum. If there are several windows of length L with the same maximum sum, choose the first.

Input format

Input input.txt

The first line contains two natural numbers `n` and `L` separated by a space. The second line contains `n` integers separated by spaces. - `1 <= L <= n <= 1000` - `-1000 <= v[i] <= 1000` - use the sliding-window technique for efficiency

Output format

Output output.txt

Print two numbers separated by a space: the position of the first element of the maximum-sum window, and the value of that sum. The line ends with a newline character.

Example

input
6 3

1 2 3 4 5 6
output
4 15

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output