题目链接
BaoBao is brewing a magical potion. To brew this potion, n
types of ingredients, whose rank ranges from 1 to n
, is needed. More precisely, for all 1 <= i <= n
, BaoBao needs at least ai
pieces of rank-i
ingredients to make the potion, while he only has bi
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 T
(about 100), indicating the number of test cases. For each test case:
The first line contains an integer n (1 <= n <= 100)
, indicating the number of types of ingredients.
The second line contains n
integers a1,a2,,,an (1 <= ai <= 1000000000)
, where ai
indicates the number of rank-i
ingredients needed.
The third line contains n
integers b1,b2,,,bn (1 <= bi <= 1000000000)
, where bi
indicates the number of rank-i
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<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL t,n,f,a[105],b[105];
int main(){
ios :: sync_with_stdio(false);
cin.tie(0);
cin >> t;
while(t--){
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= n;i++) cin >> b[i];
f = 1;
for(int i = n;i >= 1;i--){
if(b[i] < a[i]){
f = 0;
cout << "No" << endl;
break;
}
else{
b[i - 1] += b[i] - a[i];
}
}
if(f == 1){
cout << "Yes" << endl;
}
}
return 0;
}