CF1675A Food for Animals 题解

· · 题解

观察题目可以发现,我们可以用一种策略——只能喂给猫或狗的食物优先使用,最后不够的看通用食物能不能给剩下的宠物吃即可。

本题要注意特判:只能给某种宠物用的食物即使没用完也不能再用,即注意判断没吃食物的宠物数量不能小于 0

放代码:

#include<iostream>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  int t; cin>>t;
  while(t--){
    int a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    cout<<(max(x-a,0)+max(y-b,0)<=c?"Yes\n":"No\n");
  }
  return 0;
}