Cloud Retainer's Game

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

요약
공은 기울기 1 또는 -1로 움직이며 판에 부딪혀 튕긴다. 판을 골라 최대로 많은 동전을 모아야 한다.
난이도

보통10점 중 7점

유형
동적 계획법, 해시맵, 조합론, 정렬
정답자
아직 제출이 없습니다

문제

Cloud Retainer, the builder of the Dwelling in the clouds above Qingyun Peak, is very interested in mechanics. Although there is more than one month away from the Lantern Rite Festival in Liyue, she has already started the design of a gaming event for it.

Cloud Retainer and the Traveler

The game is mainly about releasing pinballs to get a score as high as possible. It is played on the 2-dimensional plane with two horizontal straight lines y=0y = 0 and y=Hy = H. Between the two lines, there are nn tiny wooden boards and mm coins, both can be regarded as single points. The ii-th wooden board is located at (x_i,y_i)(x\_i, y\_i) while the ii-th coin is located at (x′_i,y′_i)(x'\_i, y'\_i).

A pinball is released from (10−9,10−9)(10^{-9}, 10^{-9}) by the player. Let v→=(v_x,v_y)\overrightarrow{v} = (v\_x, v\_y) be the velocity of the ball (that is to say, if the ball is currently located at (x,y)(x, y) it will move to (x+v_xϵ,y+v_yϵ)(x + v\_x\epsilon, y + v\_y\epsilon) after ϵ\epsilon seconds). Initially v→=(1,1)\overrightarrow{v} = (1, 1).

When the ball hits a wooden board or one of the two horizontal straight lines, v_yv\_y will be negated (that is, v_yv\_y becomes −v_y-v\_y) while v_xv\_x remains unchanged. If the ball hits a coin, the player's score is increased by 11 and the velocity of the ball remains unchanged.

To gain a higher score, the player can choose to remove any number of wooden boards before the pinball is released. It is also OK not to remove any wooden board. Cloud Retainer wants you to help her estimate the difficulty by computing the maximum score the player can get after 101010101010^{10^{10^{10^{10}}}} seconds under the best strategy?

입력

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains one integer HH (2≤H≤1092 \le H \le 10^9).

The second line contains one integer nn (1≤n≤1051 \le n \le 10^5) indicating the number of wooden boards.

For the following nn lines, the ii-th line contains two integers x_ix\_i and y_iy\_i (1≤x_i≤1091 \le x\_i \le 10^9, 1≤y_i<H1 \le y\_i < H) indicating a wooden board located at (x_i,y_i)(x\_i, y\_i).

The following line contains one integer mm (1≤m≤1051 \le m \le 10^5) indicating the number of coins.

For the following mm lines, the ii-th line contains two integers x′_ix'\_i and y′_iy'\_i (1≤x′_i≤1091 \le x'\_i \le 10^9, 1≤y′_i<H1 \le y'\_i < H) indicating a coin located at (x′_i,y′_i)(x'\_i, y'\_i).

It's guaranteed that the given (n+m)(n + m) points in the same test case will be distinct. It's also guaranteed that neither the sum of nn nor the sum of mm of all test cases will exceed 5×1055 \times 10^5.

출력

For each test case output one line containing one integer indicating the maximum score the player can get after removing some (or not removing any) wooden boards.

힌트

The two sample test cases are shown below. Solid diamonds represent the remaining wooden boards, while hollow diamonds represent the removed wooden boards and round dots represent the coins.

Sample test case No. 1Sample test case No. 2

예제1

  1. 예제 1

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