CF2055B.Crafting

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

There are nn different types of magical materials, numbered from 11 to nn. Initially, you have aia_i units of material ii for each ii from 11 to nn. You are allowed to perform the following operation:

  • Select a material ii (where 1≤i≤n1\le i\le n). Then, spend 11 unit of every other material jj (in other words, j≠ij\neq i) to gain 11 unit of material ii. More formally, after selecting material ii, update array aa as follows: ai:=ai+1a_i := a_i + 1, and aj:=aj−1a_j := a_j - 1 for all jj where j≠ij\neq i and 1≤j≤n1\le j\le n. Note that all aja_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 bib_i units of material ii for each ii from 11 to nn. Determine if it is possible to craft the artifact by performing the operation any number of times (including zero).

正如你所料,佛罗里达州是众多奇异魔法力量的发源地,而“佛罗里达男子”正试图驯服它们。

共有 nn 种不同类型的魔法材料,编号从 11 到 nn。初始时,对每个 ii(1≤i≤n1 \le i \le n),你拥有 aia_i 单位的第 ii 种材料。你可以执行以下操作任意次(包括零次):

  • 选择一种材料 ii(其中 1≤i≤n1 \le i \le n)。然后,消耗其余每种材料 jj 各 11 单位(即对所有满足 j≠ij \neq i 且 1≤j≤n1 \le j \le n 的 jj),从而获得 11 单位材料 ii。更准确地说,选择材料 ii 后,数组 aa 按如下方式更新:ai:=ai+1a_i := a_i + 1,且对所有满足 j≠ij \neq i 且 1≤j≤n1 \le j \le n 的 jj,令 aj:=aj−1a_j := a_j - 1。注意:所有 aja_j 必须始终保持非负,即你不能消耗自己并不拥有的资源。

你希望利用这些材料来制作一件神器。要成功制作该神器,你必须对每个 ii(1≤i≤n1 \le i \le n)至少拥有 bib_i 单位的第 ii 种材料。请判断:通过执行上述操作任意次数(包括零次),是否可能达成这一目标。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i\le 10^9) — the amount of each material ii that you currently hold.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi≤1090 \le b_i\le 10^9) — the amount of each material ii needed to produce the artifact.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052\le n\le 2\cdot 10^5)—— 材料种类的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i\le 10^9)—— 你当前持有的每种材料 ii 的数量。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi≤1090 \le b_i\le 10^9)—— 制作该物品所需的每种材料 ii 的数量。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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.

对于每个测试用例,输出一行,包含“YES”或“NO”,表示该物品是否可以被制作。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    3
    4
    0 5 5 1
    1 4 4 0
    3
    1 1 3
    2 2 1
    2
    1 10
    3 3

    输出#1

    YES
    NO
    YES

说明/提示

In the first test case, perform an operation on material 11. After doing so, we will have exactly the required resources: 11 unit of material 11, and 44 units each of materials 22 and 33.

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 11 twice. After these operations, we will have 33 units of material 11 and 88 units of material 22, which is more than enough to craft the artifact.

在第一个测试用例中,对材料 11 执行一次操作。执行后,我们将恰好拥有所需的资源:11 单位材料 11,以及材料 22 和材料 33 各 44 单位。

在第二个测试用例中,可以证明:无论以何种方式执行操作,都无法制作该神器。

在第三个测试用例中,我们可以对材料 11 执行两次操作。执行后,我们将拥有 33 单位材料 11 和 88 单位材料 22,这已足以制作该神器。

输入解题思路,AI测评打分。不知道怎么写?

首页