forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
37 lines (31 loc) · 868 Bytes
/
Solution.java
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
37
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
int n = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
int tmp = sc.nextInt();
a[i] = tmp;
}
sc.close();
int counter = 0;
for (int i = 1; i <= n; i++) {
int tmpCounter = 0;
for (int k = 0; k < i; k++) {
tmpCounter += a[k];
}
if (tmpCounter < 0) { counter++; }
for (int j = i; j < n; j++) {
tmpCounter += a[j];
tmpCounter -= a[j-i];
if (tmpCounter < 0) {
counter++;
}
}
}
System.out.println(counter);
}
}