Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.util.function.*;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] a = new int[n];
- for (int i = 0; i < n; i++)
- a[i] = sc.nextInt();
- long ans = Integer.MIN_VALUE, sum = 0;
- for (int x : a) {
- sum += x;
- ans = Math.max(ans, sum);
- if (sum < 0)
- sum = 0;
- }
- System.out.println(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement