Created
November 8, 2016 06:54
-
-
Save tina1998612/e62c505777637a1bc2603b22b2bb8628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <algorithm> | |
#include <math.h> | |
#include <queue> | |
#include <iostream> | |
#include <cstring> | |
#define N 1000000 | |
#define inf 0x7f7f7f7f | |
using namespace std; | |
int cas,n,q,a[N],s,t,sum,mini; | |
void solve(){ | |
sum=0; | |
s=t=0; | |
mini=inf; | |
for(;;){ | |
while(t<n && sum<q){ | |
sum+=a[t++]; | |
} | |
if(sum<q) break; | |
mini=min(mini,t-s); | |
sum-=a[s++]; | |
} | |
} | |
int main(){ | |
scanf("%d",&cas); | |
while(cas--){ | |
scanf("%d%d",&n,&q); | |
for(int i=0;i<n;i++) scanf("%d",&a[i]); | |
solve(); | |
if(mini==inf) mini=0; | |
printf("%d\n",mini); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment