AlgoUniversity
  • Go Back
Discussion
Traveler Fund :

Author

Ayush Gangwani

Difficulty Level : Easy

Submissions : 1026

Asked In : Goldman-Sachs

Marks :10

: 10 | : 0

A traveler is traveling form city of zeta to omega. He starts with $$$X$$$ amount of money. Every day he spends some money and also he may work on some days to earn money. He may find good work some day and end up earning more than what he spends that day. It also may happen that he spends more than what he earns on any day.

You are given an array $$$A$$$ of $$$n$$$ integers which represents his net savings (earning-expense) on $$$n$$$ consecutive days. You need to find out the minimum non-negative value of $$$X$$$, the traveler should begin with to ensure that he always have some money $$$(\gt 0)$$$ at the end of any day.

Input

The first line of input contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of testcases. The description of $$$t$$$ testcases follows.

The first line of each testcase contains an integer $$$n$$$ $$$(1 \le n \le 10^{5})$$$ — the size of array $$$A$$$.

The second line of each testcase contains $$$n$$$ space separated integers $$$a_1, a_2,... a_n$$$ $$$(-10^9 \le a_i \le 10^9)$$$ — the elements of array $$$A$$$.

Output

For each testcase, print a single integer — the minimum non negative value of $$$X$$$ in a new line.

Example

Input
3
3
4 2 -3
4
-5 1 2 3
5
4 -6 1 1 -8
Output
0
6
9

Note

In sample testcase 1, if the traveler starts with an amount of 0,

  • At the end of day 1, he has $$$0+4 = 4$$$ units of money.
  • At the end of day 2, he has $$$4+2 = 6$$$ units of money.
  • At the end of day 3, he has $$$6-3 = 3$$$ units of money.
Since he always has some amount of money at the end of any day, the answer is $$$0$$$.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.