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

请大牛们指教一下为什么会 wa????

Posted by lbb10_16 at 2009-08-23 11:02:14 on Problem 3061 and last updated at 2009-08-27 12:17:25
#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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator