努力ing
你浪费的今天是昨天死去的人所渴望的明天!!!

http://acm.hdu.edu.cn/showproblem.php?pid=3177

 

#include<iostream>
#include "algorithm"
using namespace std;
struct node 
{
	int ai;
	int bi;
	int ci;
	bool operator <(const node& x)
	{
		return ci>x.ci;  //排序两者的差值
	}
};
int main()
{
	int t,i,j;
	int v,n;
	cin>>t;
	node job[10005];
	while(t--)
	{
		cin>>v>>n;
		for(i=0;i<n;i++){
			cin>>job[i].ai>>job[i].bi;
			job[i].ci=abs(job[i].ai-job[i].bi);
		}
		sort(job,job+n);
		int m=v;
		for(i=0;i<n;i++)
		{
			if(m>=job[i].bi){
				m-=job[i].ai;
			}
			else{
				break;
			}
		}
		if(i==n) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

 

posted on 2013-06-21 17:23  努力ing  阅读(148)  评论(0)    收藏  举报