P19925 [GeeksforGeeks] Maximum possible sum4134
普及-
题目描述

Given two arrays A and B of size N, the task is to find the maximum sum possible of a window in array B such that elements of the same window in array A are unique.
Example 1:
Input: N = 7
A = [0, 1, 2, 3, 0, 1, 4]
B = [9, 8, 1, 2, 3, 4, 5]
Output: 20
Explanation: The maximum sum possible
in B[] such that all corresponding
elements in A[] are unique is
(9+8+1+2) = 20.

Example 2:
Input: N = 5
A = [0, 1, 2, 0, 2]
B = [5, 6, 7, 8, 2]
Output: 21
​Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function returnMaxSum() that takes array A, array B, and integer N as parameters and returns the maximum possible sum.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

Constraints:
1 ≤ N ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
N = 7 A = [0, 1, 2, 3, 0, 1, 4] B = [9, 8, 1, 2, 3, 4, 5]
样例输出
20