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
41
42
43
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int n,s;
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st= new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken()); //물건의 개수
s = Integer.parseInt(st.nextToken()); //비교쌍의 개수
int seq[] = new int[100001];
st= new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
seq[i] = Integer.parseInt(st.nextToken());
}
int left = 0, right = 0;
long sum = seq[0];
int ans = 987654321;
while(left <= right) {
if (sum < s) {
if (right >= n-1) break;
sum += seq[++right];
}
else {
if (ans < 2) break;
sum -= seq[left++];
}
}
if (ans == 987654321) System.out.println(0);
else System.out.println(ans);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/JAVA