- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Subarray.java
More file actions
Latest commit
24 lines (22 loc) · 742 Bytes
/
Copy pathJava Subarray.java
File metadata and controls
24 lines (22 loc) · 742 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
importjava.io.*;
importjava.util.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scannerin = newScanner(System.in);
intsize = in.nextInt();
int[] arr = newint[size];
int[][] arrM = newint[size][size];
intcount = 0;
for(inti=0;i<size;i++){
arr[i] = in.nextInt();
if(arr[i] < 0) count++;
arrM[i][i] = arr[i];
for(intj=0;j<i;j++){
arrM[j][i] = arrM[j][i-1]+arr[i];
if(arrM[j][i] < 0) count++;
}
}
System.out.println(count);
}
}