-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwopointer_temp.cpp
More file actions
48 lines (37 loc) · 878 Bytes
/
Copy pathtwopointer_temp.cpp
File metadata and controls
48 lines (37 loc) · 878 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
#include <bits/stdc++.h>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define INF 987654321
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<int,int,int> tp;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector <ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef unordered_map<int, int> mpii;
int N,S;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> N >> S;
int a[N];
for(auto &i : a) cin >> i;
int s=0, e=0, sum=a[0], ans=INF;
while(s <= e && e < N){
if(sum >= S){
ans = min(ans, e-s+1);
sum -= a[s];
s++;
}
else{
e++;
sum += a[e];
}
}
if(ans == INF) cout << 0;
else cout << ans;
}//1806