#P2688. 大海战
大海战
Description
The game is played on a board. Initially, GD has types of ships. Each ship has width , length , and there are ships of the -th type. GD must place all these ships on the board so that no two ships overlap (they may be adjacent).
Next, MW makes “attacks,” each time targeting a cell, and GD will tell him whether that attack “hit” a ship (or any part of it).
Puzzlingly, GD tells MW every time that he did not hit any ship, which is clearly unrealistic. Now MW reveals the entire gameplay to you. He wants to know the earliest time, after which of his attacks, one can conclude that GD must have lied at least once.
Input Format
There are multiple test cases within a single test file.
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains three integers, the board length , the number of ship types , and the number of attacks .
- The next lines (lines to ) each contain two integers. On line , the two integers are the length and the count of the -th type of ship.
- Line contains integers. The -th integer is the position targeted by MW’s -th attack.
Output Format
For each test case, output a single integer , the earliest index such that after the -th operation you can conclude GD has lied. In particular, if it is impossible from the very beginning to place all ships as required, output . If after all attacks you still cannot determine whether GD has lied, output .
3
12 2 2
1 1
2 5
6 8
5 1 2
3 1
1 5
11 3 0
2 2
3 1
5 1
2
-1
0
Hint
-
Sample Input/Output 1 Explanation:
- For the first sample, there exists a layout ( means empty) such that the first attack misses; no layout can make both attacks miss.
- For the second sample, there exists a layout such that both attacks miss.
- For the third sample, it is impossible to place all ships legally from the start.
-
Constraints:
- For test point 1, , , .
- For test points 2–3, all are .
- For test points 2–8, , , .
- For test point 9, , , .
- For test points 10–14, , , .
- For test points 15–16, , , .
- For test points 17–20, , , .
- For of the testdata, $1 \le t \le 5, n \ge 1, c \ge 1, q \ge 0, 1 \le a_i \le n, 0 \le c_i \le 10^5, 0 \le t_i \le 10^5$.
-
Note: Please be mindful of the impact of constant factors on performance.
Translated by ChatGPT 5
京公网安备 11011102002149号