Search for the maximum sum of a subarray with unique elements
C#
Hard
arrays
Task «Search for the maximum sum of a subarray with unique elements»
Given an array of integers, find the maximum sum of a contiguous subarray in which all elements are distinct. If there are no such subarrays, output 0. Constraints: array length up to 10^5, elements modulo up to 10^9.
Input Format
The first line contains an integer N — the length of the array. The second line contains N integers separated by spaces.
Output Format
Output a single integer — the maximum sum of a subarray with unique elements.
Examples
Example 1
INPUT
4
-1 -2 -3 -4
OUTPUT
0
main.cs