-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathJavaSubarray.java
More file actions
29 lines (26 loc) · 775 Bytes
/
JavaSubarray.java
File metadata and controls
29 lines (26 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.*;
import java.util.*;
public class JavaSubarray {
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 input = new Scanner(System.in);
int n = input.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = input.nextInt();
}
int counter = 0;
// Arrays.sort(arr);
for(int i=0;i<n;i++){
int sum = 0;
for(int j=i;j<n;j++){
sum += arr[j];
if(sum < 0){
counter++;
}
}
sum = 0;
}
System.out.println(counter);
}
}