VisaOA #13
Maximum Sum by Sign-Flip Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyBits & Math
Each operation picks two distinct positions and multiplies both by −1; operations can be repeated. Find the maximum sum the array can reach.
Input
n (2≤n≤200000), n integers (−10⁹..10⁹). From the source problem's constraints.
Output
Output the maximum sum, using a 64-bit integer.
Example 1
Input:
3
-5 -1 7
Output:
13
Example 2
Input:
2
-2 -3
Output:
5
Example 3
Input:
3
0 -5 8
Output:
13
Editorial
Loading solution…