delete pics to save space
This commit is contained in:
35
history_source/挑战程序设计竞赛/3.2.1.1.cpp
Normal file
35
history_source/挑战程序设计竞赛/3.2.1.1.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
int n,S;
|
||||
int a[100005];
|
||||
void init()
|
||||
{
|
||||
scanf("%d%d",&n,&S);
|
||||
for(int i=0;i<n;i++) scanf("%d",a+i);
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
int l,r,sum,res=n+1;
|
||||
l=r=sum=0;
|
||||
while(1)
|
||||
{
|
||||
while(r<n&&sum<S) sum+=a[r++];
|
||||
if(sum<S) break;
|
||||
res=min(res,r-l);
|
||||
sum-=a[l++];
|
||||
}
|
||||
if(res>n) printf("0\n");
|
||||
else printf("%d\n",res);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
while(n-->0)
|
||||
{
|
||||
init();
|
||||
solve();
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user