A9536 | Pudding Monsters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Have you ever played Pudding Monsters? In this task, a simplified one-dimensional model of this game is used.
Imagine an infinite checkered stripe, the cells of which are numbered sequentially with integers. Some cells of the strip have monsters, other cells of the strip are empty. All monsters are made of pudding, so if there are two monsters in the neighboring cells, they stick to each other (literally). Similarly, if several monsters are on consecutive cells, they all stick together in one block of monsters. We will call the stuck together monsters a block of monsters. A detached monster, not stuck to anyone else, is also considered a block.
In one move, the player can take any block of monsters and with a movement of his hand throw it to the left or to the right. The selected monsters will slide on until they hit some other monster (or a block of monsters).
For example, if a strip has three monsters in cells $1$ , $4$ and $5$ , then there are only four possible moves: to send a monster in cell $1$ to minus infinity, send the block of monsters in cells $4$ and $5$ to plus infinity, throw monster $1$ to the right (it will stop in cell $3$ ), throw a block of monsters in cells $4$ and $5$ to the left (they will stop in cells $2$ and $3$ ).
Some cells on the strip are marked with stars. These are the special cells. The goal of the game is to make the largest possible number of special cells have monsters on them.
You are given the numbers of the special cells on a strip as well as the initial position of all monsters. What is the maximum number of special cells that will contain monsters in the optimal game?
Imagine an infinite checkered stripe, the cells of which are numbered sequentially with integers. Some cells of the strip have monsters, other cells of the strip are empty. All monsters are made of pudding, so if there are two monsters in the neighboring cells, they stick to each other (literally). Similarly, if several monsters are on consecutive cells, they all stick together in one block of monsters. We will call the stuck together monsters a block of monsters. A detached monster, not stuck to anyone else, is also considered a block.
In one move, the player can take any block of monsters and with a movement of his hand throw it to the left or to the right. The selected monsters will slide on until they hit some other monster (or a block of monsters).
For example, if a strip has three monsters in cells $1$ , $4$ and $5$ , then there are only four possible moves: to send a monster in cell $1$ to minus infinity, send the block of monsters in cells $4$ and $5$ to plus infinity, throw monster $1$ to the right (it will stop in cell $3$ ), throw a block of monsters in cells $4$ and $5$ to the left (they will stop in cells $2$ and $3$ ).
Some cells on the strip are marked with stars. These are the special cells. The goal of the game is to make the largest possible number of special cells have monsters on them.
You are given the numbers of the special cells on a strip as well as the initial position of all monsters. What is the maximum number of special cells that will contain monsters in the optimal game?
输入格式
The first line contains two integers $n$ and $m$ $(1<=n<=10^{5}; 1<=m<=2000)$ — the number of monsters on the strip and the number of special cells.
The second line contains $n$ distinct integers — the numbers of the cells with monsters, then the third line contains $m$ distinct integers — the numbers of the special cells. It is guaranteed that all the numbers of the cells are positive integers not exceeding $2·10^{5}$ .
The second line contains $n$ distinct integers — the numbers of the cells with monsters, then the third line contains $m$ distinct integers — the numbers of the special cells. It is guaranteed that all the numbers of the cells are positive integers not exceeding $2·10^{5}$ .
输出格式
Print a single integer — the maximum number of special cells that will contain monsters in the optimal game.
输入输出样例
输入 #1
3 2 1 3 5 2 4
输出 #1
2
输入 #2
4 2 1 3 4 6 2 5
输出 #2
2
输入 #3
4 2 1 8 4 5 7 2
输出 #3
1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted