NC53681 「土」巨石滚滚

贪心策略:
1.若b>=a,则a小的放在前面,减少丧失的稳定性,以防下一个a过大.
2.若b<a,则b大的放在前面.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5+5;
inline ll read()
{
    ll s = 0, w = 1; 
    char ch = getchar();
    while (ch < 48 || ch > 57) 
    	{ 
    		if (ch == '-') 
    			w = -1; 
    		ch = getchar(); 
    	}
    while (ch >= 48 && ch <= 57) 
    	s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
struct node
{
    int a,b;
    bool operator < (const node n) const
    {
        if(b >= a && n.b >= n.a) 
        	return a < n.a;
        if(b >= a) 
        	return true;
        if(n.b >= n.a)
        	return false;
        return b > n.b;
    }
}q[500005];
int main(int argc, char const *argv[])
{
	int t = read();
	while(t--)
	{
		ll n = read(), m = read(); 
		for (int i = 0; i < n; ++i)
		{
			q[i].a = read();
			q[i].b = read();
		}
		sort(q, q+n);
		bool flag = true;
		for (int i = 0; i < n; ++i)
		{
			if (m < q[i].a)
			 {
			 	flag = false;
			 	break;
			 } 
			 m += (q[i].b - q[i].a);
		}
		if (flag)
		{
			cout << "Yes" << endl;
		}
		else
			cout << "No" << endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值