hdu1871贪心

#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
	int number,num,price;
}hotel[1009];
int cmp(node a,node b)
{
	return a.price<b.price;
}
int main()
{   int T,n,i,t,g,m; 
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d",&hotel[i].number,&hotel[i].num,&hotel[i].price);
		}
		sort(hotel+1,hotel+n+1,cmp);
		scanf("%d",&t);
		while(t--)
		{
			scanf("%d",&m);g=0;
		    for(i=1;i<=n;i++)
		    {
		    	if(hotel[i].num>=m)
		       {
				 printf("%d\n",hotel[i].number);
				 hotel[i].num=hotel[i].num-m;
				 g=1;
				 break;
		       } 
		    }
		    if(g==0) printf("sorry\n");
		}
	}
}

 

posted @ 2013-04-15 12:51  宛如  阅读(162)  评论(0)    收藏  举报