Liquid Distribution

시간 제한2초메모리 제한1024 MB

요약
두 액체를 섞은 n개의 병에서 일부를 덜어 m개의 목표 병에 지정된 양만큼 A와 B를 각각 담을 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
기하, 그리디, 수학
정답자
아직 제출이 없습니다

문제

After years of space exploration, humans succeeded in bringing back a small amount of sample materials from an asteroid to Earth! The materials were stored in several bottles, each containing a complete mixture of two liquids, A and B.

Intense discussion finally reached an agreement that all the materials brought back should be distributed to the research institutes participated in the exploration. The amounts of the liquids A and B to be sent were decided depending on the research topics of each of the institutes.

However, after this decision, a problem was found that it is impossible with current human technologies to separate two liquids from the mixture. The only operations we can perform are to take some amounts of the mixtures from one or more bottles and put them together in a new bottle.

Your task is to judge whether the agreed distribution of the liquids is possible ever.

입력

The input consists of a single test case of the following format.

nn mm

a_1a\_1 ⋯\cdots a_na\_n

b_1b\_1 ⋯\cdots b_nb\_n

c_1c\_1 ⋯\cdots c_nc\_n

d_1d\_1 ⋯\cdots d_nd\_n

Here, nn is the number of the bottles initially containing the mixtures of liquid A and liquid B, while mm is the number of the research institutes to which liquids are to be sent. Both nn and mm are positive integers not greater than 500500. The following two lines contain nn integers each, meaning that the ii-th bottle (1≤i≤n1 ≤ i ≤ n) initially contains the mixture of a_ia\_i mL of liquid A and b_ib\_i mL of liquid B. The following two lines contain mm integers each, meaning that a bottle containing c_jc\_j mL of liquid A and d_jd\_j mL of liquid B is to be sent to the jj-th institute (1≤j≤m1 ≤ j ≤ m). All of a_ia\_i, b_ib\_i, c_jc\_j and d_jd\_j are positive integers not greater than 10610^6. Both ∑_i=1na_i=∑_j=1mc_j\sum\_{i=1}^{n}{a\_i} = \sum\_{j=1}^{m}{c\_j} and ∑_i=1nb_i=∑_j=1md_j\sum\_{i=1}^{n}{b\_i} = \sum\_{j=1}^{m}{d\_j} hold.

출력

If the agreed distribution is possible, output Yes; otherwise, output No in a line.

힌트

For Sample Input 1, the only way that conforms to the decision is to send 0.50.5 mL from the bottle 11 and 2.52.5 mL from the bottle 22 put together in a bottle to the institute 11, and a bottle of the rest to the institute 22.

For Sample Input 2, the distribution agreement cannot be fulfilled.

예제4

  1. 예제 1

    입력
    2 2
    1 3
    3 1
    2 2
    1 3
    
    예상 출력
    Yes
    
  2. 예제 2

    입력
    2 2
    2 2
    2 2
    1 3
    3 1
    
    예상 출력
    No
    
  3. 예제 3

    입력
    3 5
    2 5 8
    3 5 7
    3 3 3 3 3
    3 3 3 3 3
    
    예상 출력
    Yes
    
  4. 예제 4

    입력
    3 2
    4 4 4
    1 9 5
    6 6
    2 13
    
    예상 출력
    No