Uniqueness violation

2.5

4 votes
Basic Programming, Basics of Implementation, Easy, Implementation
Problem

You are given with an integer N. You are provided with an array of exactly N integers denoted by Ai. Also, you are provided with the uniqueness value for each array element and is denoted as Ui. Your task is to pick the array elements in such a way that no two adjacent array elements picked have the same value of uniqueness and the sum of values picked is maximum.

Input format

  • First line: Integer T denoting the total number of test cases

For each test case:

  • First line: Integer N
  • Next line: N integers corresponding to the uniqueness value Ui
  • Next line: N integers each corresponding to the value Ai

Output format
Print a single integer corresponding to each test case denoting the maximum possible sum of values that are selected.

Constraints
1T1001N1051Ai1041Ui109

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

The best way to maximize sum of values is to pick element 2 (with value 30), element 3 (with value 15), element 4 (with value 16) and element 8 (with value 24). 
Answer = 30+15+16+24=85.

Editor Image

?