CF1494C.1D Sokoban

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are playing a game similar to Sokoban on an infinite number line. The game is discrete, so you only consider integer positions on the line.

You start on a position 00 . There are nn boxes, the ii -th box is on a position aia_i . All positions of the boxes are distinct. There are also mm special positions, the jj -th position is bjb_j . All the special positions are also distinct.

In one move you can go one position to the left or to the right. If there is a box in the direction of your move, then you push the box to the next position in that direction. If the next position is taken by another box, then that box is also pushed to the next position, and so on. You can't go through the boxes. You can't pull the boxes towards you.

You are allowed to perform any number of moves (possibly, zero). Your goal is to place as many boxes on special positions as possible. Note that some boxes can be initially placed on special positions.

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of testcases.

Then descriptions of tt testcases follow.

The first line of each testcase contains two integers nn and mm ( 1n,m21051 \le n, m \le 2 \cdot 10^5 ) — the number of boxes and the number of special positions, respectively.

The second line of each testcase contains nn distinct integers in the increasing order a1,a2,,ana_1, a_2, \dots, a_n ( 109a1<a2<<an109-10^9 \le a_1 < a_2 < \dots < a_n \le 10^9 ; ai0a_i \neq 0 ) — the initial positions of the boxes.

The third line of each testcase contains mm distinct integers in the increasing order b1,b2,,bmb_1, b_2, \dots, b_m ( 109b1<b2<<bm109-10^9 \le b_1 < b_2 < \dots < b_m \le 10^9 ; bi0b_i \neq 0 ) — the special positions.

The sum of nn over all testcases doesn't exceed 21052 \cdot 10^5 . The sum of mm over all testcases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each testcase print a single integer — the maximum number of boxes that can be placed on special positions.

输入输出样例

  • 输入#1

    5
    5 6
    -1 1 5 11 15
    -4 -3 -2 6 7 15
    2 2
    -1 1
    -1000000000 1000000000
    2 2
    -1000000000 1000000000
    -1 1
    3 5
    -1 1 2
    -2 -1 1 2 5
    2 1
    1 2
    10

    输出#1

    4
    2
    0
    3
    1

说明/提示

In the first testcase you can go 55 to the right: the box on position 11 gets pushed to position 66 and the box on position 55 gets pushed to position 77 . Then you can go 66 to the left to end up on position 1-1 and push a box to 2-2 . At the end, the boxes are on positions [2,6,7,11,15][-2, 6, 7, 11, 15] , respectively. Among them positions [2,6,7,15][-2, 6, 7, 15] are special, thus, the answer is 44 .

In the second testcase you can push the box from 1-1 to 109-10^9 , then the box from 11 to 10910^9 and obtain the answer 22 .

The third testcase showcases that you are not allowed to pull the boxes, thus, you can't bring them closer to special positions.

In the fourth testcase all the boxes are already on special positions, so you can do nothing and still obtain the answer 33 .

In the fifth testcase there are fewer special positions than boxes. You can move either 88 or 99 to the right to have some box on position 1010 .

首页