-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSub_array.java
More file actions
36 lines (34 loc) · 936 Bytes
/
Sub_array.java
File metadata and controls
36 lines (34 loc) · 936 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
30
31
32
33
34
35
36
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
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 [] ar = new int[n];
for(int i = 0; i < ar.length; i++)
{
ar[i] = sc.nextInt();
}
int counter = 0;
for(int i = 0; i < ar.length; i++)
{
for(int j = i; j < ar.length; j++)
{
int sum = 0;
for(int k = i; k <= j; k++)
{
sum += ar[k];
}
if(sum < 0)
counter++;
}
}
sc.close();
System.out.println(counter);
}
}