AmazonOA #207
Get Max Skill Sum
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesHashing
Employees are arranged by index, and each expertise is 0 or 1. Choose a contiguous range in which the two types have equal counts, and maximize the total skill. Choosing nobody is allowed and gives 0.
Input
The first line contains n, the second line n skill values, and the third line n 0/1 expertise flags. This site uses 1≤n≤200000, −10^9≤skill≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
3
2 3 5
0 1 1
Output:
5
Example 2
Input:
4
-5 -5 8 9
0 1 0 1
Output:
17
Example 3
Input:
2
-1 -2
0 1
Output:
0
Example notes
The answers are 5, 17 and 0.
Editorial
Loading solution…