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

    技术2026-01-05  7

    题目链接

    题意:

    给你两种不同的糖果和顾客,一个顾客是哪种糖果少拿哪种,另一个顾客是哪种糖果多拿哪种,问你是否存在一种顾客光临的顺序使得糖果能够满足所有顾客的需求。

    思路:

    哪种多拿哪种的顾客肯定是能够满足的(在有糖果的前提下,不用考虑两种各有多少),所以我们只需要考虑另一种顾客的需求即可,如果这种顾客大于开始时糖果中较少的一种的数量,那么根本不可能满足,所以我们要判断这两者之间的关系并确定后者拿完后前者有足够的糖果拿即可。

    代码:

    #include<bits/stdc++.h> using namespace std; #define int long long #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N=2e5+5; const int mod=998244353; const int inf=0x7fffffff; const double pi=3.1415926535; using namespace std; signed main() { IOS; int t; cin>>t; while(t--) { int a,b,n,m; cin>>a>>b>>n>>m; if(a>b) swap(a,b); if(m>a||n+m>a+b) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } } return 0; }
    Processed: 0.047, SQL: 12