Potion

Potion
Time Limit: 1 Second Memory Limit: 65536 KB
BaoBao is brewing a magical potion. To brew this potion, types of ingredients, whose rank ranges from 1 to , is needed. More precisely, for all , BaoBao needs at least pieces of rank- ingredients to make the potion, while he only has pieces of these ingredients in his storeroom.

Fortunately, BaoBao is able to downgrade a higher rank ingredient to a lower rank one (this operation can be performed any number of times, including zero time). Is it possible that BaoBao can make the potion using the ingredients in his storeroom?

Input
There are multiple test cases. The first line of the input contains an integer (about 100), indicating the number of test cases. For each test case:

The first line contains an integer (), indicating the number of types of ingredients.

The second line contains integers (), where indicates the number of rank- ingredients needed.

The third line contains integers (), where indicates the number of rank- ingredients BaoBao has in his storeroom.

Output
For each test case output one line. If BaoBao is able to brew the potion, output “Yes” (without quotes), otherwise output “No” (without quotes).

Sample Input
2
3
3 3 1
1 2 5
3
3 1 2
5 2 1
Sample Output
Yes
No
Hint
For the first sample test case, BaoBao can downgrade one rank-3 ingredient to a rank-2 ingredient, and downgrade two rank-3 ingredients to two rank-1 ingredients.

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>

using namespace std;
typedef long long ll;


int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int a[n], b[n];
        for (int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for (int i=0;i<n;i++)
            scanf("%d",&b[i]);
        for (int i=0;i<n;i++)
        {
            for (int j=i;j<n;j++)
            {
                if (b[j] > 0 && a[i] > 0)
                {
                    if (b[j] >= a[i])
                    {
                        b[j] -= a[i];
                        a[i] = 0;
                    }
                    else
                    {
                        a[i] -= b[j];
                        b[j] = 0;
                    }
                }
            }
        }
        int d = 1;
        for (int i=0;i<n;i++)
        {
            if (a[i] > 0)
            {
                d = 0;
                break;
            }
        }
        if (d)
            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、付费专栏及课程。

余额充值