forked from sPredictorX1708/Ultimate-Java-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaSubarray.java
More file actions
26 lines (25 loc) · 667 Bytes
/
JavaSubarray.java
File metadata and controls
26 lines (25 loc) · 667 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
import java.util.*;
public class test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>(n);
for(int i = 0; i<n ; i++){
int s = sc.nextInt();
a.add(s);
}
int tot = 0;
for(int i = 0;i<n;i++){
for(int j = i;j<n;j++){
int sum = 0;
for(int k = i;k<=j;k++){
sum+=a.get(k);
}
if(sum<0){
tot++;
}
}
}
System.out.println(tot);
}
}