Treasures
InterviewTime limit2sMemory limit32 MB
Given n piles generated by a recurrence, find the shortest consecutive block whose sum is at least the sum of all other piles.
- Level
Medium5 of 10
- Topics
- Sliding window, Two pointers, Array
- Solved
- No attempts yet
Problem
And that is what became of me, Jim. All because in my youth I went to the graveyard to play heads or tails!
Ben Gunn
Being the only person on the island, Ben Gunn lost his mind. He split the treasure in the cave into piles and laid them out in a row. Now he keeps seeing Captain Flint, who wants to take part of the treasure from him.
Since Flint is only a hallucination, his demands are unusual. He wants to take piles that lie consecutively in the row, so that the total value of these piles is at least the total value of all the other treasure. The number of piles must be as small as possible.
Ben Gunn cannot say what the value of each pile is. He only remembers the values of the first two piles, and that he computed the value of the -th pile by the formula
where , , , and are constants that Nick Allardyce gave him, and and are the values of the -th and -th piles.
Help Ben Gunn give part of his treasure to Flint.
Input
The first line contains (), the number of piles. The second line contains and (), the values of the first two piles. The third line contains , , , and ().
Output
Print the numbers of the first and the last piles Flint should take. If there are several answers, print any of them.
Hint
Note that memory is limited in this problem.