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

那位大牛救救我!受不了了!到底哪错了!总过不去!不胜感激!

Posted by li4951 at 2009-02-22 16:12:16 on Problem 2487
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int testcases = 0;
	int t = 1;
//	freopen("2487.txt", "r", stdin);
	cin >> testcases;
	while(testcases)
	{
		int sum = 0;
		int need = 0;
		int peonum = 0;
		int sign = 0;
		cin >> need >> peonum;
		int *data;
		data = new int[peonum];
		int i = 0;
		for(i = 0; i < peonum; i++)
		{
			cin >> data[i];
		}
		sort(data, data + peonum);
		for(i = peonum - 1; i >= 0; i--)
		{
			sum += data[i];
			if((sum > need) && ((sum - data[i]) >= need))
			{
				sign = 1;
				break;
			}
		}
		cout << "Scenario #" << t++ << ":" << endl;
		if(sign == 1)
		{
			cout << (peonum - 1) - i << endl;
		}
		else cout << "impossible" <<endl;
		testcases--;
		cout << endl;
	}
	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