Problem title
Difficulty
Avg time to solve

Rotate Function
Moderate
25 mins
Remove Edges
Moderate
20 mins
Query And Matrix
Moderate
50 mins
Moderate
25 mins
Mobile Pattern Lock.
Moderate
30 mins
Glowing Bulbs
Hard
30 mins
Concatenate The Largest Digit
Easy
15 mins
Maximum Number Of Eaten Apples
Moderate
15 mins
Kronecker Product Of Two Matrices
Easy
20 mins
Stepping Numbers
Moderate
30 mins

Maximum Number Of Eaten Apples

Difficulty: MEDIUM
Contributed By
Avg. time to solve
15 min
Success Rate
85%

Problem Statement

Note :

``````1) It is also possible that the tree doesn’t grow any apples on any particular day, i.e., ’APPLES[i]’ = 0 for ‘i’th day.
2) ‘DAYS[i]’ = 0 if and only if ‘APPLES[i]’ = 0.
3) You can keep eating apples even after ‘N’ days, but keep in mind that you can eat at most one apple per day.
``````
Input Format :
``````The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.

The first line of each test case contains a positive integer ‘N’ denoting the size of the arrays.

The second line of each test case contains N space-separated non-negative integers denoting the elements of the array ‘APPLES’.

The third line of each test case contains N space-separated non-negative integers denoting the elements of the array ‘DAYS’.
``````
Output Format :
``````For each test case, print the maximum number of apples you can eat.

Output for each test case will be printed in a separate line.
``````
Note :
``````You do not need to print anything. It has already been taken care of. Just implement the given function.
``````
Constraints :
``````1 <= T <= 100
1 <= N <= 3000
0 <= ‘APPLES[i]’, ‘DAYS[i]’  <= 3000

Where 'APPLE[i]' and 'DAYS[i]' denotes the ith element of respective array.

Time Limit: 1sec
``````
Sample Input 1 :
``````1
5
1 2 0 4 1
2 2 0 3 1
``````
Sample Output 1 :
``````6
``````
Explanation For Sample Input 1 :
``````You can eat 6 apples as follows:
On the 1st day, you can eat the apple produced by the tree on day 1.
On the 2nd day, you can eat the apple produced by the tree on day 2.
On the 3rd day, you can eat the apple produced by the tree on day 2.
From the 4th to the 6th day, you can eat the apple produced by the tree on day 4.
``````
Sample Input 2 :
``````1
3
2 0 2
2 0 1
``````
Sample Output 2 :
``````3
``````
Explanation For Sample Input 2 :
``````You can eat 3 apples as follows:
On the 1st day, you can eat the apple produced by the tree on day 1.
On the 2nd day, you can eat the apple produced by the tree on day 1.
On the 3rd day, you can eat the apple produced by the tree on day 3. After this day, we are having 1 more apple but it becomes inedible on the 4th day.
``````
Console