G - The baggage 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 600

問題文

重さが 1 , 2 , 3 , 4 , 55 種類の重さの荷物があり、重さが i (1 \leq i \leq 5) の荷物はそれぞれ A_i 個あります。
また、体力が 1 , 2 , 3 , 4 , 55 種類の体力の人がおり、体力が i (1 \leq i \leq 5) の人はそれぞれ B_i 人います。
それぞれの人は 0 個以上の任意の個数の荷物を持つことができますが、重さの合計が体力を超えるような組合せで荷物を持つことはできません。

T 個のテストケースが与えられます。 それぞれのケースに対して、うまく分担してすべての荷物を持つことは可能か判定してください。すなわち、各人に割り当てられた荷物の重さの総和がその人の体力を超えないように、すべての荷物を誰かに割り当てることが可能か判定して下さい。荷物を 1 つも持たない人がいても構いません。

制約

  • 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
  • 入力は全て整数である。

入力

入力は標準入力から与えられる。入力の 1 行目にはテストケース数 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) 行目には、i 番目のテストケースについてすべての荷物を持つことが可能なら Yes を、そうでないならば 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

1 つめのテストケースでは、例えば以下のようにすればすべての荷物を持つことができます。

  • 体力 4 の人のうちの 1 人目が、重さ 1 の荷物を 4 つ持つ。
  • 体力 4 の人のうちの 2 人目が、重さ 1 の荷物と重さ 2 の荷物を 1 つずつ持つ。
  • 体力 5 の人が、重さ 5 の荷物を 1 つ持つ。

2 つめのテストケースでは、体力が 3 の人のどちらかが重さ 2 の荷物を 2 つ以上持つ必要があり、不可能です。

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.