import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; /** * Solution to Overdraft * * @author vanb */ public class overdraft_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** * Do it! */ private void doit() { int n = sc.nextInt(); // We've got to make sure we can cover the worst balance. int balance = 0; int worst = 0; while( n-->0 ) { int t = sc.nextInt(); balance += t; worst = Math.min( worst, balance ); } // If the worst is -5, then we need to start with a balance of 5. // But, if the worst is 3, we don't start with a balance of -3, we start with 0. // A negative balance makes no sense. ps.println( Math.max( 0, -worst ) ); } /** * Main. * * @param args unused * @throws Exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new overdraft_vanb().doit(); } }