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

RunError Why?

Posted by alzhu at 2008-12-15 19:07:02 on Problem 2487
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm> 
using namespace std;


int main()
{
	int a,b,d,e,f,k,impossible;
	scanf("%d",&a);
	for(int i=1;a--;i++)
	{
		scanf("%d%d",&b,&f);
		int *c=new int[b];
		for(int j=0;j<f;j++)
		{
			scanf("%d",&c[j]);
		}
		sort(&c[0],&c[f]);
		d=0;
		impossible=0;
		for(k=f-1,e=0;d<b;k--,e++)
		{
			if(k<0)
			{
				impossible=1;
			}
			d+=c[k];
		}
		printf("Scenario #%d:\n",i);
		if(!impossible)
			printf("%d\n\n",e);
		else
			printf("impossible\n\n");
		delete [] c;
	}
	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