2055B.md (2896B)
1 Source: https://codeforces.com/problemset/problem/2055/B 2 3 B. Crafting 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 | | 22 | --- | 23 | As you'd expect, Florida is home to many bizarre magical forces, and Florida Man seeks to tame them. | 24 25 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: 26 27 * 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. 28 29 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). 30 31 Input 32 33 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. 34 35 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. 36 37 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. 38 39 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. 40 41 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 42 43 Output 44 45 For each test case, print a single line containing either "YES" or "NO", representing whether or not the artifact can be crafted. 46 47 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. 48 49 Example 50 51 Input 52 53 ``` 54 3 55 56 4 57 58 0 5 5 1 59 60 1 4 4 0 61 62 3 63 64 1 1 3 65 66 2 2 1 67 68 2 69 70 1 10 71 72 3 3 73 ``` 74 75 Output 76 77 ``` 78 YES 79 NO 80 YES 81 ``` 82 83 Note 84 85 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$. 86 87 In the second test case, it can be shown that no matter how the operations are performed, it is impossible to craft the artifact. 88 89 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.