102266: [AtCoder]ABC226 G - The baggage

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

We have parcels with five different weights: $1$, $2$, $3$, $4$, $5$. For each $i$ $(1 \leq i \leq 5)$, there are $A_i$ parcels of weight $i$.
Additionally, we have people with five different strengths: $1$, $2$, $3$, $4$, $5$. For each $i$ $(1 \leq i \leq 5)$, there are $B_i$ people with strength $i$.
Each person can carry any number of parcels (possibly zero), but the total weight of the parcels must not exceed their strength.

You are given $T$ test cases. For each case, determine whether it is possible for the people to carry all parcels with the appropriate allocation of parcels. That is, determine whether it is possible to allocate each parcel to someone so that each person is allocated parcels whose total weight does not exceed their strength. It is fine to have someone who carries no parcels.

Constraints

  • $1 \leq T \leq 5\times 10^4$
  • $0 \leq A_i,B_i \leq 10^{16}$
  • $1 \leq A_1+A_2+A_3+A_4+A_5$
  • $1 \leq B_1+B_2+B_3+B_4+B_5$
  • All values in input are integers.

Input

Input is given from Standard Input. The first line contains the number of test cases $T$:

$T$

Then, $T$ test cases follow, each in the following format:

$A_1$ $A_2$ $A_3$ $A_4$ $A_5$
$B_1$ $B_2$ $B_3$ $B_4$ $B_5$

Output

Print $T$ lines. The $i$-th line $(1\leq i\leq T)$ should contain Yes if all parcels can be carried in the $i$-th test case, and No otherwise.


Sample Input 1

3
5 1 0 0 1
0 0 0 2 1
0 3 0 0 0
0 0 2 0 0
10000000000000000 0 0 0 0
0 0 0 0 2000000000000000

Sample Output 1

Yes
No
Yes

In the first test case, all parcels can be carried. Here is one way to do so:

  • The first person with strength $4$ carries four parcels of weight $1$.
  • The second person with strength $4$ carries one parcel of weight $1$ and another of weight $2$.
  • The person with strength $5$ carries one parcel of weight $5$.

In the second test case, one of the two people with strength $3$ has to carry two or more parcels of weight $2$, which is impossible.

Input

Output

得分:$600$分

问题描述

我们有五种不同重量的包裹:$1$,$2$,$3$,$4$,$5$。对于每个$i$ $(1 \leq i \leq 5)$,有$A_i$个重量为$i$的包裹。

此外,我们有五种不同力量的人:$1$,$2$,$3$,$4$,$5$。对于每个$i$ $(1 \leq i \leq 5)$,有$B_i$个力量为$i$的人。

每个人可以携带任意数量的包裹(包括零个),但包裹的总重量不得超过他们的力量。

您将获得$T$个测试用例。 对于每个用例,确定是否有可能让人们通过适当的包裹分配来携带所有包裹。也就是说,确定是否有可能将每个包裹分配给某个人,以便每个人被分配的包裹的总重量不超过他们的力量。有人没有携带包裹是可以的。

约束

  • $1 \leq T \leq 5\times 10^4$
  • $0 \leq A_i,B_i \leq 10^{16}$
  • $1 \leq A_1+A_2+A_3+A_4+A_5$
  • $1 \leq B_1+B_2+B_3+B_4+B_5$
  • 输入中的所有值都是整数。

输入

输入从标准输入给出。第一行包含测试用例的数量$T$:

$T$

然后,跟随$T$个测试用例,每个用例如下格式:

$A_1$ $A_2$ $A_3$ $A_4$ $A_5$
$B_1$ $B_2$ $B_3$ $B_4$ $B_5$

输出

打印$T$行。 第$i$行 $(1\leq i\leq T)$ 应包含Yes,如果在第$i$个测试用例中可以携带所有包裹,否则包含No


样例输入 1

3
5 1 0 0 1
0 0 0 2 1
0 3 0 0 0
0 0 2 0 0
10000000000000000 0 0 0 0
0 0 0 0 2000000000000000

样例输出 1

Yes
No
Yes

在第一个测试用例中,所有包裹都可以携带。以下是一种方法:

  • 力量为$4$的第一人携带四个重量为$1$的包裹。
  • 力量为$4$的第二人携带一个重量为$1$的包裹和另一个重量为$2$的包裹。
  • 力量为$5$的人携带一个重量为$5$的包裹。

在第二个测试用例中,力量为$3$的两个人中的一个必须携带两个或更多的重量为$2$的包裹,这是不可能的。

加入题单

算法标签: