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

Why I got wa!!

Posted by subdragon at 2003-11-02 16:34:00 on Problem 1456
#include<iostream.h>
#include<stdlib.h>
struct node
	{
		int p,d;
	}s[10010];
int cmp(const void *a,const void *b) 
{ 
   struct node  *c = (struct node   *)a; 
   struct node  *d = (struct node   *)b; 
   return c->p < d->p; 
} 
int arrange[10010];

int main()
{

	int i,j,n,t; double sum;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
			cin>>s[i].p>>s[i].d;
		for(i=1;i<=10000;i++)
			arrange[i]=-1;
		qsort(s,n,sizeof(struct node),cmp);
		sum=0;
		for(i=0;i<n;i++)
		{
			t=s[i].d;
    		while(t)
				{
					if(arrange[t]==-1) 
					{
						sum+=s[i].p;
						arrange[t]=0;
						break;
					}
					t--;
				}         
		}
		cout<<sum<<endl;
	}
}

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