
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the number of movies.
The second line contains ‘N’ space-separated integers denoting the time required to watch these ‘N’ movies.
For each test case, print the minimum time required for Bucky and Steve to watch ‘N’ movies under the given conditions.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
1 <= N <= 10^6
1 <= MOVIES[i] <= 10^9
Where 'MOVIES[i]’ is the duration of the ‘i-th’ movie.
Time limit: 1 sec.
The basic idea of finding minimum time is to check if the maximum element is greater than the sum of the rest of the elements in the array. The minimum time required will be twice the maximum element. As when one of them is watching the movie with the maximum time duration, the other can complete the rest of the movies in the same time. Similarly, when the second one watches that longest movie, the first one can watch the rest of the movies.
The other case will be when the maximum element is less than the sum of all others. Then there will be only one optimal option, i.e., one of them will watch the movie in increasing order of time duration, and the other will watch it in decreasing order of time duration. In this case, the answer will be the sum of the time duration of all the movies.
Algorithm