개요[ | ]
- HR자바 Java Subarray
Java
Copy
import java.io.*;
import java.util.*;
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 scan = new Scanner(System.in);
int n = scan.nextInt();
int[] a = new int[n];
for(int i=0; i<n; i++) a[i] = scan.nextInt();
scan.close();
int sum, cnt = 0;
for(int i=0; i<n; i++) {
sum = 0;
for(int j=i; j<n; j++) {
sum += a[j];
if( sum < 0 ) cnt++;
}
}
System.out.println(cnt);
}
}
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.