NOI Contest Archive

Archive / 2022 / May 2022

Run, Barry, Run!

Easy · National Olympiad in Informatics Sri Lanka - May 2022

You are Barry Allen - the fastest man alive. You need to travel back in time to prevent a major catastrophe from taking place. You can only do this by opening up a Time Rift. A Time Rift will open up only if you achieve a very fast speed.

Looking around, you notice multiple terrains. Each terrain consists of slopes and plains. After running around the world millions of times, you know the gains in speed (in machs) you can achieve running down any given slope and the losses in speed after running up one. It’s plain as day (pun intended) that there is no speed to be gained or lost running across a plain.

You have examined each terrain as N number of blocks. Each block has a value which is given as,

After starting your run at any point of your choosing, what is the maximum speed you can reach at the end of the terrain? Choose where you start wisely.

Input Format

First line contains the number of test cases T.

For each of the T test cases,

Output Format

Constraints

Sample Input 0

2
3
0 3 -1
5
2 3 -4 1 -2

Sample Output 0

2
0