BETA

Difficulty Level: Easy

Submissions: 233 Accuracy:

30.9%

Maximum possible sum
       

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

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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