当前位置: 首页 > 工具软件 > potion > 使用案例 >

Potion

芮承运
2023-12-01

 


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 <cstring>
#define maxn 110
using namespace std;
int main() {
    int t;
    long long a[maxn];
    long long b[maxn];
    cin >> t;
    while (t --) {
        int n;
        cin >> n;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for (int i = 0;i < n; i ++) {
            cin >> a[i];
        }
        for (int i = 0;i < n; i ++) {
            cin >> b[i];
        }
        int flag = 0;
        for (int i = n - 1; i >= 1; i --) {
            if (b[i] - a[i] >= 0) {
                b[i] -= a[i];
                b[i - 1] += b[i];
            } else if (b[i] - a[i] < 0) {
                flag = 1;
                break;
            }
        }
        if (b[0] - a[0] >= 0 && flag == 0) {
            flag = 0;
        } else {
            flag = 1;
        }
        if (flag == 1) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

 

相关阅读

相关文章

相关问答