#P14822. [ICPC 2023 Yokohama R] Liquid Distribution

[ICPC 2023 Yokohama R] Liquid Distribution

题目描述

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.

$$\begin{aligned} & n \ m \\ & a_1 \ \cdots \ a_n \\ & b_1 \ \cdots \ b_n \\ & c_1 \ \cdots \ c_m \\ & d_1 \ \cdots \ d_m \\ \end{aligned}$$

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 500. The following two lines contain nn integers each, meaning that the ii-th bottle (1in1 \leq i \leq n) initially contains the mixture of aia_i mL of liquid A and bib_i mL of liquid B. The following two lines contain mm integers each, meaning that a bottle containing cjc_j mL of liquid A and djd_j mL of liquid B is to be sent to the jj-th institute (1jm1 \leq j \leq m). All of aia_i, bib_i, cjc_j and djd_j are positive integers not greater than 10610^6. Both i=1nai=j=1mcj\sum_{i=1}^{n} a_i = \sum_{j=1}^{m} c_j and i=1nbi=j=1mdj\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.

2 2
1 3
3 1
2 2
1 3
Yes
2 2
2 2
2 2
1 3
3 1
No
3 5
2 5 8
3 5 7
3 3 3 3 3
3 3 3 3 3
Yes
3 2
4 4 4
1 9 5
6 6
2 13
No

提示

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

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