Uniqueness violation
Practice
2.5 (4 votes)
Basic programming
Basics of implementation
Easy
Implementation
Problem
39% Success 2422 Attempts 20 Points 3s Time Limit 256MB Memory 1024 KB Max Code

You are given with an integer \(N\). You are provided with an array of exactly \(N\) integers denoted by \(A_i\). Also, you are provided with the uniqueness value for each array element and is denoted as \(U_i\). 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 \(U_i\)
  • Next line: \(N\) integers each corresponding to the value \(A_i\)

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

Constraints
\(1\le T \le 100\\ 1 \le N \le10^5\\ 1 \le A_i \le 10^4\\ 1\le U_i \le 10^9\\\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
45 votes
Tags:
Ad-HocApprovedEasyOpen
Points:20
5 votes
Tags:
C++Basic Programming
Points:20
319 votes
Tags:
Ad-HocEasyOpen