-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1806.cpp
More file actions
36 lines (35 loc) · 755 Bytes
/
Copy path1806.cpp
File metadata and controls
36 lines (35 loc) · 755 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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <limits.h>
#define NUM 100000
// #define MAX 1000000000
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
long N , M;
cin >> N >> M;
vector<long> arr(N);
for(long i =0;i<N;i++){
cin >> arr[i];
}
long result = LONG_MAX, sum = 0, right = 0, left = 0;
while(1){
if(sum >= M){
sum -= arr[left++];
if(result > right-left){
result = right-left +1;
}
}
else if(right == N) break;
else sum += arr[right++];
}
if(result == LONG_MAX){
cout << 0;
return 0;
}
cout << result;
return 0;
}