#K37887. Maximum Consecutive Sum

    ID: 26076 Type: Default 1000ms 256MiB

Maximum Consecutive Sum

Maximum Consecutive Sum

Given a sequence of n integers, your task is to find the maximum sum of a subsequence where the elements form a set of consecutive integers. In other words, you need to select a group of numbers from the given sequence that can be rearranged to form a sequence of consecutive numbers, and their total sum should be maximum among all such possible groups.

For example, given the array [4, 7, 5, 8, 3, 6], the sorted order is [3, 4, 5, 6, 7, 8]. Since all these numbers are consecutive, the maximum sum is 33. The input consists of multiple test cases. For each test case, first an integer n is given which denotes the number of elements, followed by n integers.

inputFormat

The first line contains an integer T, the number of test cases. Then for each test case, the first line contains an integer n, the number of elements in the array. The next line contains n space-separated integers.

outputFormat

For each test case, output a single line containing the maximum sum of a consecutive elements subsequence.## sample

3
5
1 2 3 4 5
6
4 7 5 8 3 6
4
10 20 30 40
15

33 40

</p>