-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBipartite-Matching.java
More file actions
40 lines (33 loc) · 1.15 KB
/
Copy pathBipartite-Matching.java
File metadata and controls
40 lines (33 loc) · 1.15 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
34
35
36
37
38
39
40
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class programmers_1806 {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] split = bufferedReader.readLine().split(" ");
int n = Integer.parseInt(split[0]);
int s = Integer.parseInt(split[1]);
split = bufferedReader.readLine().split(" ");
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(split[i]);
}
int partSum = 0;
int left = 0;
int right = 0;
int answer = n+1;
while (left < n && right < n){
while (right < n && (partSum + nums[right]) < s){
partSum += nums[right];
right++;
}
if (right < n && partSum + nums[right] >= s){
answer = Math.min(answer, right - left + 1);
}
partSum -= nums[left];
left++;
}
System.out.println(answer % (n+1));
}
}