#P16736. [GKS 2019 #E] Code-Eat Switcher

[GKS 2019 #E] Code-Eat Switcher

Problem Description

Umon is a foodie coder. Do you know what two activities that he loves the most? Of course, coding and eating! He always spends the whole day doing only those two activities. However, he thinks that some times of the day are better spent coding, and others are better spent eating.

To illustrate this problem, Umon divides his day into SS time slots. During the i-th time slot, if Umon codes 100% of the time, he will achieve CiC_i units of coding. On the other hand, if he eats 100% of the time, he will achieve EiE_i units of eating. But of course, Umon can also use only a fraction of the time for coding, and the remaining for eating. Formally, he will choose a real number ff (0f10 \le f \le 1), code for ff of the time, and use the remaining (1f)(1 - f) time to eat. This way, he will achieve f×Cif \times C_i units of coding and (1f)×Ei(1 - f) \times E_i units of eating. The total amount of coding Umon achieves for the day is simply the sum of all units of coding he achieved in each of the time slots. The total amount of eating is calculated in a similar way.

Umon needs to plan his schedule for the next DD days. On the i-th day, he needs to achieve at least a total amount of AiA_i units of coding and BiB_i units of eating. For each day, determine whether there is a way for Umon to achieve his target.

Input Format

The first line of input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing two integers DD and SS, the number of days and the number of time slots in a day, respectively.

Then SS lines follow, each describing a time slot. The i-th line contains two integers CiC_i and EiE_i, the amount of coding units achieved if Umon codes for 100% of the time slot, and the amount of eating units achieved if he eats for 100% of the time slot, respectively.

Then DD lines follow, each describing a day. The i-th line contains two integers AiA_i and BiB_i, the minimal total amount of coding and eating that needs to be achieved on that day.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is a string with D characters, where the i-th character is Y if there exists a schedule that can fulfill the target for the i-th day, otherwise it should be N.

2
4 2
3 8
6 10
0 18
3 13
10 0
7 3
1 2
4 4
4 4
0 0
Case #1: YYNY
Case #2: Y

Hint

In the first sample case, there are 4 days and 2 time slots for each day.

  • For day 1, Umon can just eat 100%100\% for both time slots, and therefore achieving a total of 0 units of coding and 8+10=188 + 10 = 18 units of eating, thus reaching the target.
  • For day 2, Umon can eat 100%100\% of the time for the first time slot, and use 50%50\% of the second time slot for coding and 50%50\% for eating, achieving a total of 0×3+0.5×6=30 \times 3 + 0.5 \times 6 = 3 units of coding, and 1×8+0.5×10=131 \times 8 + 0.5 \times 10 = 13 units of eating, thus reaching the target.
  • For day 3, it is impossible to get a total of 10 units of coding.
  • For day 4, there are an infinite amount of ways to achieve the target. One possible strategy is to code 42%42\% (and eat 58%58\%) in the first time slot, then code 98.76%98.76\% (and eat 1.24%1.24\%) in the second time slot. That strategy yields a total of 0.42×3+0.9876×6=7.18560.42 \times 3 + 0.9876 \times 6 = 7.1856 units of coding, and 0.58×8+0.0124×10=4.7640.58 \times 8 + 0.0124 \times 10 = 4.764 units of eating.

Thus, the answer should be YYNY.

In the second sample case, note that the value of characteristics for the time slots may not necessarily be different from each other.

Limits

1T1001 \le T \le 100.

1Ci1041 \le C_i \le 10^4, for all ii.

1Ei1041 \le E_i \le 10^4, for all ii.

0Ai1080 \le A_i \le 10^8, for all ii.

0Bi1080 \le B_i \le 10^8, for all ii.

Test set 1 (Visible)

1S21 \le S \le 2.

1D101 \le D \le 10.

Test set 2 (Hidden)

For at least 75% of the test cases:

1S1031 \le S \le 10^3.

1D1031 \le D \le 10^3.

For all test cases:

1S1051 \le S \le 10^5.

1D1051 \le D \le 10^5.