欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2055B.Crafting
Crafting
| As you'd expect, Florida is home to many bizarre magical forces, and Florida Man seeks to tame them. |
|---|
There are different types of magical materials, numbered from to . Initially, you have units of material for each from to . You are allowed to perform the following operation:
- Select a material (where ). Then, spend unit of every other material (in other words, ) to gain unit of material . More formally, after selecting material , update array as follows: , and for all where and . Note that all must remain non-negative, i.e. you cannot spend resources you do not have.
You are trying to craft an artifact using these materials. To successfully craft the artifact, you must have at least units of material for each from to . Determine if it is possible to craft the artifact by performing the operation any number of times (including zero).
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the number of types of materials.
The second line of each test case contains integers () — the amount of each material that you currently hold.
The third line of each test case contains integers () — the amount of each material needed to produce the artifact.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single line containing either "YES" or "NO", representing whether or not the artifact can be crafted.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first test case, perform an operation on material . After doing so, we will have exactly the required resources: unit of material , and units each of materials and .
In the second test case, it can be shown that no matter how the operations are performed, it is impossible to craft the artifact.
In the third test case, we can perform the operation on material twice. After these operations, we will have units of material and units of material , which is more than enough to craft the artifact.
Samples
3
4
0 5 5 1
1 4 4 0
3
1 1 3
2 2 1
2
1 10
3 3
YES
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |