• + 0 comments

    My solution - As simple as it can get:

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int sum=0;
        int negSub = 0;
        String[] arr = new String[num];
        scan.nextLine();
        String n = scan.nextLine();
        arr = n.split(" ");
        for(int i=0;i<num;i++){
    
            for(int j=i+1;j<=num;j++){
                sum=0;
                String[] subArray = Arrays.copyOfRange(arr, i,j);
                 //System.out.println(Arrays.toString(subArray));
                 for(int w=0;w<subArray.length;w++){
                    sum+=Integer.parseInt(subArray[w]);
                 }
                 if(sum<0){
                    negSub++;
                   }
                  //System.out.println(sum);
            }  
        }
       System.out.println(negSub);
    
    
         scan.close();
    

    } }