Codeforces Round 996 (Div. 2)
B
Crafting
Codeforces
1000
原题
← AC →
翻译中…

As you'd expect, Florida is home to many bizarre magical forces, and Florida Man seeks to tame them.

翻译中…

There are $n$ different types of magical materials, numbered from $1$ to $n$. Initially, you have $a_i$ units of material $i$ for each $i$ from $1$ to $n$. You are allowed to perform the following operation:

翻译中…
  • Select a material $i$ (where $1\le i\le n$). Then, spend $1$ unit of every other material $j$ (in other words, $j\neq i$) to gain $1$ unit of material $i$. More formally, after selecting material $i$, update array $a$ as follows: $a_i := a_i + 1$, and $a_j := a_j - 1$ for all $j$ where $j\neq i$ and $1\le j\le n$. Note that all $a_j$ 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 $b_i$ units of material $i$ for each $i$ from $1$ to $n$. 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 $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$) — the number of types of materials.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i\le 10^9$) — the amount of each material $i$ that you currently hold.

翻译中…

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($0 \le b_i\le 10^9$) — the amount of each material $i$ needed to produce the artifact.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

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 $1$. After doing so, we will have exactly the required resources: $1$ unit of material $1$, and $4$ units each of materials $2$ and $3$.

翻译中…

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 $1$ twice. After these operations, we will have $3$ units of material $1$ and $8$ units of material $2$, which is more than enough to craft the artifact.

翻译中…

样例

Input #1
3
4
0 5 5 1
1 4 4 0
3
1 1 3
2 2 1
2
1 10
3 3
Output #1
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2055B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。