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

## Re:请大牛们指教一下为什么会 wa？？？？

Posted by qunwanghong at 2009-08-31 18:47:55 on Problem 3061
In Reply To:请大牛们指教一下为什么会 wa？？？？ Posted by:lbb10_16 at 2009-08-23 11:02:14
```> #include <iostream>
> #include <stdlib.h>
> using namespace std;
>
> int cmp ( const void *a , const void *b )
> {
> 	return *(int *)a - *(int *)b;
> }
>
> int main()
> {
> 	int t, a[100000];
> 	int i, count;
> 	long int n, s, sum;
> 	scanf("%d", &t);
> 	while (t--)
> 	{
> 		count = 0;
> 		sum   = 0;
> 		scanf("%ld %ld", &n, &s);
> 		for (i =0; i < n; i++ )
> 			scanf("%d", &a[i]);
> 		qsort(a, n, sizeof(a[0]), cmp);
> 		for (i = n-1; i >= 0; i--)
> 		{
> 			sum += a[i];
> 			count ++;
> 			if(sum >= s)
> 			{
> 				printf("%d\n", count);
> 				break;
> 			}
> 		}
> 		if (s > sum) printf("%d\n", 0);
> 	}
> 	return 0;
> }
```

Followed by: