Bird and maximum fruit gathering
Submissions: 3550   Accuracy:

17.69%

  Difficulty: Easy   Marks: 2

There are N trees in a circle. Each tree has a fruit value associated with it. A bird has to sit on a tree for 0.5 sec to gather all the fruits present on the tree and then the bird can move to a neighboring tree. It takes the bird 0.5 seconds to move from one tree to another. Once all the fruits are picked from a particular tree, she can’t pick any more fruits from that tree. The maximum number of fruits she can gather is infinite.

Given N and M (the total number of seconds the bird has), and the fruit values of the trees. We have to maximize the total fruit value that the bird can gather. The bird can start from any tree.

Input:
The first line contains a positive integer T denoting the number of test cases. Each of the test case consists of 2 lines. The first line of each test case contains two integers N and M. Next line contains space separated sequence of N integers denoting the fruit value of each tree.

Output:
For each test case, print in a new line, the maximum number of fruits the bird can gather. As the results can be large, print your answer modulo 109+7.

Constraints:
1 <= T <= 103
1 <= N, M <= 105

Example:
Input:
2
7 3
2 1 3 5 0 1 4
6 2
1 6 2 5 3 4

Output:
9
8

Explanation:
Assume 0-based indexing.
Testcase 1 : She can start from tree 1 and move to tree2 and then to tree 3. Hence, total number of gathered fruits = 1 + 3 + 5 = 9.

Testcase 2 : She can start from tree 1 and move to tree 2. In this case she will gather 6 + 2 = 8 fruits. She can also start from tree 3 and move to tree 4. In this case, too, she will gather 5 + 3 = 8 fruits.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sajal Agrawal
Author: sajalagrawal


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.