Traveler Fund

Company: Goldman sachs_27july

Difficulty: medium

Problem Statement

Traveler Fund Problem Description A traveler is travelling from the city of Zeta to the city of Omega. He begins the journey carrying an amount X of money. On each day of the journey he spends some money, and on some days he also works and earns money. On a good day he may earn more than he spends; on a bad day he may spend more than he earns. You are given an array of N integers, where the value for day i is the traveler's net saving on that day (earnings minus expenses). The money he carries at the end of a day is his starting amount plus the net savings of all days up to and including that day. Find the smallest non-negative starting amount X such that, at the end of every one of the N days, the money he is carrying is strictly greater than 0 . Input Format The first line contains a single integer N , the number of days (the length of the array). Each of the next N lines contains a single integer: the net saving for that day, given in order from day 1 to day N . Output Format Print