Max Sum (1003)


package test;

import java.util.Scanner;

public class Main {    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int all = sc.nextInt();    
        int count = 0;
        while(count<=all){                        
            int n=sc.nextInt();
            int sum = 0, max = -0xfffffff;                
            int tstart=1;
            int tend = 1;
            int start = 1;
            int end = 1;
            for (int  j= 1; j<= n; j++){                    
                int a = sc.nextInt();
                if(sum+a<0){
                    tstart = j;
                    tend = j;
                    sum = a;
                }else{        
                    tend = j;
                    sum = sum+a;
                }
                if(sum>max){
                    start = tstart;
                    end = tend;
                    max = sum;                            
                }                    
            }
            count++;
            System.out.println("Case "+count+":");
            System.out.println(max+" "+start+" "+end);                
            if(count!=all)
                System.out.println();            
        }
    }            
}



你可能感兴趣的:(Max Sum (1003))