 Maximum possible sum
Submissions: 591   Accuracy: 33.27%   Difficulty: Easy   Marks: 2

Given two arrays A and B of equal number of elements. The task is to find the maximum sum possible of a window in array B such that elements of same window in array A are unique.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.  First line of each test case starts with an integer N denoting the size of the arrays A and B. Second line of input contains N space separated integers Of array A. And third line of input contains N space separated integers Of array B.

Output:
For each test case, print the maximum possible sum In new line.

Constraints:
1<=T<=300
1<=N<=104

0<=A[i]<=106
0<=B[i]<=106

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

Output:
20
21

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

Contributor: Arun Tyagi
Author: arun03

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.