#K51387. Maximum Beauty Subsegment
Maximum Beauty Subsegment
Maximum Beauty Subsegment
You are given T test cases. For each test case, you are provided with a sequence of n integers. The beauty of a subsegment is defined as the sum of distinct elements in that subsegment.
Formally, for a subarray \(A[i \ldots j]\) (0-indexed), let \(S\) be the set of distinct integers in that subarray. The beauty of the subsegment is defined as \(\sum_{x \in S} x\). Your task is to determine the maximum beauty among all subsegments of the sequence for each test case.
inputFormat
The first line contains an integer T, denoting the number of test cases.
For each test case:
- The first line contains an integer n, the length of the sequence.
- The second line contains n space‐separated integers representing the sequence.
outputFormat
For each test case, output a single line containing the maximum beauty of any subsegment in the sequence.
## sample3
6
8 2 2 8 3 5
5
1 2 2 3 4
4
4 4 4 4
18
10
4
</p>