子序列最大和

package 排序;

import java.util.Scanner;

public class dome {
    public static int max(int a,int b)
    {
        if(a > b)
            return a;
        else
        {
            return b;
        }
    }


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int []a = new int[10010];
        int []res = new int[10010];
        int n,k = 0,x = 0,ans = -5000;
        n = sc.nextInt();
        for(int i = 1; i <= n; i ++)
        {
            a[i] = sc.nextInt();
            if(a[i] < 0)x ++;
            res[i] = max(0,res[i-1] + a[i]);
            k = max(res[i],k);
            
        }
        System.out.println(k);
    }

}

 

posted @ 2022-03-12 21:37  爽爽子的秃头生活  阅读(21)  评论(0)    收藏  举报