Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## TLE了，哪里抄了，帮忙给改改吧，谢谢！！

Posted by 771385494 at 2011-11-06 17:58:01 on Problem 3061
```#include <iostream>
using namespace std;
int main()
{
int nCases,n,tag,i,j,array[100000];
cin >> nCases;
while(nCases--){
cin >> n >> tag;
int total = 0,max = 0,sum = 0,length = n + 1,tmp = n + 1;
for(i = 0;i < n;i++){
cin >> array[i];
if(array[i] > max)
max = array[i];
total += array[i];
}
if(max >= tag){
cout << "1" << endl;
break;
}
if(total < tag){
cout << "0" << endl;
continue;
}
if(total == tag){
cout << n << endl;
continue;
}
int *p1 = array,*p2;
for(i = 0;i < n;i++){
p2 = p1;
for(j = i;j < n;j++){
sum += *p2;
p2++;
if(sum >= tag)
break;
}
if(sum >= tag){
tmp = p2 - p1;
if(tmp < length)
length = tmp;
if(length == 1)
break;
}
p1++;
sum = 0;
}
if(length == n + 1)
cout << "0" << endl;
else
cout << length << endl;
}
return 0;
}
```

Followed by: