Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution{
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int t = sc.nextInt();
- StringBuilder ans = new StringBuilder("");
- while (t-- > 0) {
- int n = sc.nextInt();
- int[] arr = new int[n];
- for(int i=0;i<n;i++){
- arr[i] = sc.nextInt();
- }
- long max_so_far = Long.MIN_VALUE, max_ending_here = 0;
- for(int i=0;i<n;i++){
- max_ending_here = max_ending_here + arr[i];
- max_so_far = Math.max(max_so_far,max_ending_here);
- if (max_ending_here < 0)
- max_ending_here = 0;
- }
- ans.append(max_so_far+"\n");
- }
- System.out.println(ans);
- }
- }
Add Comment
Please, Sign In to add comment