#C5893. Maximum Earned Points with Mandatory Skip
Maximum Earned Points with Mandatory Skip
Maximum Earned Points with Mandatory Skip
You are given several test cases. In each test case, you are presented with a list of tasks, where each task has an associated point value. Your goal is to earn the maximum points possible with the constraint that you must skip at least one task.
More formally, for each test case:
- If the number of tasks N is exactly 2, you can only complete one of them, so the answer is the maximum of the two values.
- If N is greater than 2, you can skip exactly one task. It is always optimal to skip the task with the minimum point value, meaning the maximum points equal the total sum of points minus the smallest point value.
Note: The input is read from standard input and the output is printed to standard output.
inputFormat
The first line of input contains an integer T (1 ≤ T ≤ 100), the number of test cases. Each test case begins with an integer N (2 ≤ N ≤ 105), representing the number of tasks, followed by a line containing N space-separated integers (each between 0 and 109) representing the points for each task.
outputFormat
For each test case, output a single integer on a new line: the maximum points that can be earned under the constraint that at least one task is skipped. The answer is computed as follows:
- If N = 2, output max(task1, task2).
- If N > 2, output sum(all tasks) - min(task values).
2
4
1 2 3 4
5
0 1 0 2 5
9
8
</p>