ZOJ 2018校赛 E Potion

版权声明:虽然我依旧蒟蒻,但请你尊重我 :D   ——陈杉菜 https://blog.csdn.net/qq_44702847/article/details/89302511

157 - The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) - E

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.

大声bb

从最高级的药开始制,如果条件不允许,就是手上的碎片不够那肯定做不成
够的话就把所有的剩下的药转变成下一级的药。。。
应该是水的,可惜水平太差,没有很快的打出来,好吧,wa的原因主要是没开long long???
心塞塞

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<map>
#include<set>
#include<queue> 
#include<iomanip>
#include<list>
#include<fstream>
using namespace std;
typedef long long ll;
bool f=true;
ll a[110];
ll b[110];
int main(){
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		f=true;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%lld",&b[i]);//xuyaode
		}
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]);//youde
		}
		for(int i=n;i>=1;i--){
			int k=i;
			if(a[k]>=b[k]){
				a[k-1]=a[k-1]+(a[k]-b[k]);
			}
			else {
				f=false;
				break;
			}
		}
		if(f && a[0]>=0) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44702847/article/details/89302511