-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain2.java
More file actions
33 lines (32 loc) · 1.1 KB
/
Copy pathMain2.java
File metadata and controls
33 lines (32 loc) · 1.1 KB
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
import java.io.*;
public class Main2 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] firstLine = br.readLine().split(" ");
int n = Integer.parseInt(firstLine[0]);
long k = Long.parseLong(firstLine[1]);
long[] a = new long[n];
String[] secondLine = br.readLine().split(" ");
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(secondLine[i]);
}
long totalCount = 0;
for (int l = 0; l < n; l++) {
long currentSum = 0;
long maxInInterval = Long.MIN_VALUE;
long target = k;
for(int r=l;r<n;r++){
currentSum += a[r];
if(currentSum>maxInInterval){
maxInInterval = currentSum;
}
if(maxInInterval==target){
totalCount++;
}else if(maxInInterval>target){
break;
}
}
}
System.out.println(totalCount);
}
}