#K46932. Maximum Sum after Deleting One Element

    ID: 28086 Type: Default 1000ms 256MiB

Maximum Sum after Deleting One Element

Maximum Sum after Deleting One Element

You are given an array of integers. Your task is to remove exactly one element from the array such that the sum of the remaining elements is maximized. Formally, if the array is (a_1, a_2, \dots, a_n) with total sum (S = \sum_{i=1}^{n}a_i), then after deleting the element (a_j), the remaining sum is (S - a_j). You need to determine the maximum possible value of (S - a_j) for all valid (j).

Note that there can be multiple test cases in the input.

inputFormat

The first line contains an integer (T) denoting the number of test cases. Each test case consists of two lines: the first line contains an integer (N) (the number of elements in the array) and the second line contains (N) space-separated integers.

outputFormat

For each test case, output one line containing a single integer — the maximum sum obtainable by deleting exactly one element from the array.## sample

1
5
1 -2 3 -1 2
5

</p>