Want to solve this problem? Login now to get access to solve the problems

Problem

Submissions

Solution

Leaderboard

Coming soon

0

Difficulty: EASY

Avg. time to solve

20 min

Success Rate

80%

Problem Statement

Suggest Edit

```
All trees are in a circle
```

```
Input: N=7 M=3
arr[] = { 2 ,1 ,3 ,5 ,0 ,1 ,4 }
Output: 9
Explanation:
She can start from tree 1 and move to tree 2 and then to tree 3.
Hence, total number of gathered fruits = 1 + 3 + 5 = 9.
```

```
The first line of input contains a single integer ‘T’ denoting the number of test-cases for the problem.
The first line of each test case in the input contains two space-separated integers ‘N’ and ‘M’ denoting the number of trees and the seconds given to collect the fruits from the trees.
And the second line contains single space-separated integers, denoting the fruits on each tree.
```

```
return the maximum number of fruits the ninja bird can gather in the given amount of time.
Note: You do not need to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 100
1 <= M <= 5000
1 <= N <= 5000
1 <= ARR[i] <= 5000
Time Limit: 1 sec
```

```
2
6 2
1 6 2 5 3 4
7 3
2 1 3 5 0 1 4
```

```
8
9
```

```
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. Therefore the answer here is 8.
She can start from tree 1 and move to tree
2 and then to tree 3. Hence, the total number of gathered fruits = 1 + 3 + 5 = 9.
```

```
1
8 3
2 3 4 1 2 1 5 3
```

```
10
```

Want to solve this problem? Login now to get access to solve the problems