| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:怎么能WA呢???????????In Reply To:怎么能WA呢??????????? Posted by:tcxgsy at 2006-11-04 18:53:07 /*Source
Problem Id:3061 User Id:others_code
Memory:580K Time:109MS
Language:G++ Result:Accepted
* Source*/
#include<iostream>
using namespace std;
int a[100002];
int main()
{
int tests;
int m,n;
int i,j;
int sum;
scanf("%d", &tests);//cin>>tests;~~~~~use scanf to avoid TLE
while(tests--)
{
scanf("%d%d", &m, &n);//cin>>m>>n;
for(i=0;i<m;i++)
scanf("%d", &a[i]);//cin>>a[i];
i=0;
int min=2147483647;~~~~~use a larger number, 'cause sum maybe large
sum=0;
j=0;
while(j<=i&&i<=m)
{
if(sum<n) {sum+=a[i];i++;}
if(sum>=n) {
if(i-j<min) min=i-j;
sum-=a[j];
j++;
}
}
if(min==2147483647)~~~~it should be in this way
cout<<0<<endl;
else
cout<<min<<endl;
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator