| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Why I got wa!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator