Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,S;
- int row[100005];
- int main(){
- scanf("%d%d",&n,&S);
- for(int i=1;i<=n;i++)
- scanf("%d",&row[i]);
- int l,r;
- l = r = 1;
- int sum = row[1];
- int ans = -1;
- while(r <= n){
- if(sum >= S){
- if(ans == -1)
- ans = r-l+1;
- else
- ans = min(ans,r-l+1);
- if(l!=r){
- sum -= row[l];
- l++;
- }
- else{
- r++;
- sum += row[r];
- }
- }
- else{
- r++;
- sum += row[r];
- }
- }
- printf("%d",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement