Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save manish-manghwani/26f6df2895a0a31fabd57353ec0a39cb to your computer and use it in GitHub Desktop.

Select an option

Save manish-manghwani/26f6df2895a0a31fabd57353ec0a39cb to your computer and use it in GitHub Desktop.
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 sc = new Scanner(System.in);
int n = sc.nextInt();
int[] inputArr = new int[n];
for(int i=0; i<n; i++) {
inputArr[i] = sc.nextInt();
}
int count=0;
int k = 0;
for(int i=0; i<n; i++) {
int innerSum = 0;
for(int j = k; j<n ; j++) {
if( (innerSum + inputArr[j] ) < 0 ){
count++;
}
innerSum += inputArr[j];
}
k++;
}
System.out.println(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment