-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1806.cpp
More file actions
59 lines (38 loc) · 762 Bytes
/
1806.cpp
File metadata and controls
59 lines (38 loc) · 762 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include <string>
using namespace std;
int arr[100001];
int main(void)
{
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N, S; cin >> N >> S;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
int start = 0, end = 0;
int min = 1234567;
int nowVal = 0;
nowVal += arr[end];
while (start != N) {
if (nowVal >= S) {
if (min > end - start + 1)min = end - start + 1;
nowVal -= arr[start];
start++;
}
else {
if (end != N - 1) {
end++;
nowVal += arr[end];
}
else {
break;
}
}
}
if (min == 1234567)cout << "0";
else cout << min;
}