Codeforces Round 993 (Div. 4)
菜~~
F Easy Demon Problem
References:
- Codeforces Round 993 (Div. 4) Editorial
- Codeforces Round 993 (Div. 4)
F. Easy Demon Problem
Description
For an arbitrary grid, Robot defines its beauty to be the sum of elements in the grid.
Robot gives you an array
of length and an array of length . You construct a by grid such that for all and . Then, Robot gives you
queries, each consisting of a single integer . For each query, determine whether or not it is possible to perform the following operation exactly once so that has a beauty of :
- Choose integers
and c such that and - Set
to be for all ordered pairs such that , , or both. Note that queries are not persistent, meaning that you do not actually set any elements to
in the process — you are only required to output if it is possible to find and such that if the above operation is performed, the beauty of the grid will be . Also, note that you must perform the operation for each query, even if the beauty of the original grid is already .
Input
The first line contains three integers $n,
, and — the length of , the length of , and the number of queries respectively. The second line contains
integers . The third line contains
integers . The following
lines each contain a single integer , the beauty of the grid you wish to achieve by setting all elements in a row and a column to .
Output
For each testcase, output "YES" (without quotes) if there is a way to perform the aforementioned operation such that the beauty is
, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
Examples
1 | 3 3 6 |
1 | NO |
1 | 5 5 6 |
1 | YES |
Note
In the second example, the grid is
0 -2 5 0 -3
0 4 -10 0 6
0 -6 15 0 -9
0 0 0 0 0
0 0 0 0 0
By performing the operation with
and , we create the following grid: 0 0 5 0 -3
0 0 -10 0 6
0 0 15 0 -9
0 0 0 0 0
0 0 0 0 0
which has beauty
. Thus, we output YES. In the second query, selecting
and creates a grid with beauty . In the third query, selecting
and creates a grid with beauty .
Solution
- 参考 F - Easy Demon Problem - tourist
做的时候,把式子拆开了,没简化出乘积形式(thoughtforces)
根据题意有
而题述的operation
对
因此,要使
仅需要找
而在实现中,如果通过遍历每一个
因此我们只需要查找是否存在对应的
1 |
|