
The first line of the input 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 tasks.
The second line of each test case contains ‘N’ space-separated integers, representing the time needed to complete each task.
For each test case, print the minimum time needed to complete the homework.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5*10^3
Time Limit : 1 sec
For any ‘ith’ task we have two choices with us whether to include the ‘ith’ task or exclude the ‘ith’ task.
We can maintain an array to keep track of time.
Here is the algorithm :
The idea is similar to the previous approach. We only use the time of ‘i - 1’th task for the ‘ith’ task. So we can save the space by using variables that will store the time of the previous task.
Here is the algorithm :