SABBIRGAME - Sabbir and Game

no tags 

Sabbir is a little boy. he loves  to play. One day his friend taskin suggested a new interesting game. there are n levels in the game. one should pass all the levels with a positive life-point. in some level one can increase his life-point by defeating the villain of the game or lose some life-point when one can't defeat the villain. Sabbir knows the points he is going to lose or increase in each level. determine the mnimum life-point sabbir should have initially ( at the starting of the game ) to pass all the levels with a positive life point.


input consists of at most 100 test cases.

first line consists of a single integer T ( 1 <= T <= 100) number of test cases

each test case is consists of two lines. first line consists of an integer n ( 1 <= n <= 1000 )

second line consists of n space separated integer  a1 , a2 ..... an-1 , an ( -107 <= ai  <= 107 ) 


for each test case print an integer in one line , the minimum life-point sabbir will need initially.


5 -8 3
1 2 -3 5
1 0 3
first case, if sabbir have 4 life-points at first. sabbir will have 9 points after playing 1st level, he will have 1 point after playing 2nd level, he will have 4 points after playing 3rd level... his points never  becomes less than 1 (remains positive) . if he start with a lower point ( less than 4) initially, he will die at the 2nd level and can't pass all the levels. so, 4 is the minimum ans.

hide comments
limon_88: 2019-04-28 21:24:37

Nice Problem @sabbir vai

ashutoshkumar6: 2019-01-08 19:23:52

ohh,finally got ac...

jareehd: 2018-11-05 17:58:35

my 50th
but it takes 40 days

sanyam19: 2018-01-04 10:10:01

used a good concept of ternary operator.... :)

aditya_rev: 2017-06-21 18:40:09

pls check for submission id 19654968. could u tell me where is the bug? thx before

itissabbir: 2017-04-30 09:27:52

@sachinverma there is a mistake in your code. I can't tell that in comments. try to find out.

Sachin verma: 2017-04-27 20:11:10

@sabbir will you please check my submission. I cannot understand my mistake. Thank you.

Marcin: 2017-03-18 22:07:28

What should be the answer for the following test case:

Should it be 0 or 1?

Edit: got it, it's 1

Last edit: 2017-03-18 22:15:57
Somdip Sen: 2017-03-14 11:44:17

sd_singh: what is it you need ?

Karsten Ari Agathon: 2017-03-07 07:28:05

I think it will be better if stated that the minimum life-point initially must larger or equal to 0.

Added by:sabbir
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)