Unequal Goodness
Practice
5 (2 votes)
Data structures
Advanced data structures
Segment trees
Problem
42% Success 722 Attempts 30 Points 4s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of \(N\) integers. A subarray from \(l\) to \(r\) \((l < r)\) is good if \(A[l] != A[r]\).
You have to find the \(maximum\) possible \(sum\) of elements of a good subarray. If there is no such good subarray then print "Not Possible".
Input Format:
- The first line contains an integer \(T\), which denotes the number of test cases.
- The first line of each test case contains \(N\).
- The second line of each test case contains \(N\) space-separated integers, denoting the elements of array \(A\).
Output Format:
For each test case, print the maximum possible sum of elements of good subarray or print "Not Possible" (without double quotes) if there is no such good subarray.
Constraints:
\(1 \leq T \leq 10 \\ 2 \leq N \leq 2*10^5 \\ -10^9 \leq A[i] \leq 10^9\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Advanced Data StructuresData StructuresGCDImplementationNumber theorySegment Trees
Points:30
1 votes
Tags:
Data StructuresMediumSegment Trees
Points:30
12 votes
Tags:
Data StructuresMediumOpenSegment TreesTrees
Editorial