Codeforces Round #654 (Div. 2)——C. A Cookie for You

C. A Cookie for You

题目描述
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has a vanilla cookies and b chocolate cookies for the party.She invited n guests of the first type and m guests of the second type to the party. They will come to the party in some order. After coming to the party, each guest will choose the type of cookie (vanilla or chocolate) to eat. There is a difference in the way how they choose that type:
If there are v vanilla cookies and c chocolate cookies at the moment, when the guest comes, then

  • if the guest of the first type: if v>c the guest selects a vanilla
    cookie. Otherwise, the guest selects a chocolate cookie.
  • if the guest of the second type: if v>c the guest selects a
    chocolate cookie. Otherwise, the guest selects a vanilla cookie.

After that:

  • If there is at least one cookie of the selected type, the guest eats
    one.
  • Otherwise (there are no cookies of the selected type), the guest gets
    angry and returns to home.

Anna wants to know if there exists some order of guests, such that no one guest gets angry. Your task is to answer her question.
Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.For each test case, the only line contains four integers a, b, n, m (0≤a,b,n,m≤1018,n+m≠0).
Output
For each test case, print the answer in one line. If there exists at least one valid order, print “Yes”. Otherwise, print “No”.You can print each letter in any case (upper or lower).
input

6
2 2 1 2
0 100 0 1
12 13 25 1
27 83 14 25
0 0 1 0
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000

output

Yes
No
No
Yes
No
Yes

题意思路:就是给你两种饼干a和b,两类人n和m,如果a>b,n类人可以吃一块a饼干,m类人可以吃一块b饼干,若b>=a,则n类人可以吃一块b饼干,m类人可以吃一块a饼干。

  • 【不管是a>b还是a<b,n类人两种饼干都可以吃(a>b就吃a,a<b就吃b)】(故最后处理这个,只要剩的a+b大于n的值)
  • m类人则不然,a>b的时候吃b(导致b就再也不可能比a大了),a<b的时候吃a(同样,导致a就再也不可能比b大了)。

至此我们就可以推出,只要m能够全部吃到饼干,n只需判断m吃剩的就可以了,转换成数学思维就是:a饼干和b饼干的总和要大于n类人和m类人的总和,还有一点就是

m类人先吃(且只能单方面吃一种饼干,即数量少的饼干——因为a>b的时候吃b,a<b的时候吃a)

所以要保证较少的饼干数要大于m类人的人数。

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long int a,b,n,m;
        scanf("%lld%lld%lld%lld",&a,&b,&n,&m);
        if (a+b>=n+m&&min(a,b)>=m)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值