Hi.

In above problem the last test case is looking inappropriate to me. The last array is [1, 2, 5] and the length of it is 3 so X could be [3, 4, 6] as 1≤X≤2⋅N .

If I append 6, the array is [ 1, 2, 5, 6 ] and total = 0

If I append 4 the array is [1 ,2 ,5 ,6,4] and total is 6 - 4 = 2

If I append 3 the array is [1, 2, ,5 ,6, 4, 3] and total = 6- 3 = 3

so my max total is 2 + 3 = 5 which does not match with their calculation .

Please guide me.