O(n)
O(n)
import java.util.Scanner; public class Main { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i ++){ arr[i] = sc.nextInt(); } int[] dp = new int[n]; dp[0] = arr[0]; int ans = dp[0]; for(int i=1;i<n;i++){ dp[i] = Math.max(dp[i-1] + arr[i], arr[i]); if(dp[i] > ans){ ans = dp[i]; } } System.out.println(ans); } } /* 7 1 -2 3 5 -2 6 -1 12 */