Erase to max

3.5

8 votes
Basic Programming, Basics of Implementation, Easy, Implementation
Problem

You are given an array A of size N. You have to select any value 'x' from A and remove its all occurrences. You need to perform this operation exactly once.

You need to obtain the maximum possible final sum of A.

Input format

  • First line: A number T denoting the total number of test cases

For each test case:

  • First line: A number N denoting size of A
  • Next line: N space-separated integers denoting the array A

Output format
Print the maximum possible sum of A after performing the operation exactly once.

Constraints

1T10
1N105
1A[i]106

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

In testcase 1, x = 1. So, sum is 3. This is maximum sum that can be obtained.
In testcase 2, x = 1. So, sum is 5. This is maximum sum that can be obtained.

Editor Image

?