import java.util.*;


public class Solution {
    /**
     * max sum of the subarray
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxsumofSubarray (int[] arr) {
        // write code here
        if(arr == null){
            return 0;
        }

        int[] dp = new int[arr.length];
        for(int i = 0; i < arr.length; ++i){
            if(i == 0){
                dp[i] = arr[i];
            }else{
                if(dp[i - 1] < 0){
                    dp[i] = arr[i];
                }else{
                    dp[i] = dp[i - 1] + arr[i];
                }
            }
        }

        int maxV = Integer.MIN_VALUE;
        for(int i = 0; i < dp.length; ++i){
            maxV = Math.max(maxV, dp[i]);
        }
        return maxV;
    }
}