Max Sum (1003)

来源:互联网 发布:linux cp mv 编辑:程序博客网 时间:2024/06/01 15:30


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();                    }    }            }


0 0
原创粉丝点击