A8406 | Matchmaker
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarpus has $n$ markers and $m$ marker caps. Each marker is described by two numbers: $x_{i}$ is the color and $y_{i}$ is the diameter. Correspondingly, each cap is described by two numbers: $a_{j}$ is the color and $b_{j}$ is the diameter. Cap $(a_{j},b_{j})$ can close marker $(x_{i},y_{i})$ only if their diameters match, that is, $b_{j}=y_{i}$ . Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, $a_{j}=x_{i}$ .
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
输入格式
The first input line contains two space-separated integers $n$ and $m$ ( $1<=n,m<=10^{5}$ ) — the number of markers and the number of caps, correspondingly.
Next $n$ lines describe the markers. The $i$ -th line contains two space-separated integers $x_{i}$ , $y_{i}$ ( $1<=x_{i},y_{i}<=1000$ ) — the $i$ -th marker's color and diameter, correspondingly.
Next $m$ lines describe the caps. The $j$ -th line contains two space-separated integers $a_{j}$ , $b_{j}$ ( $1<=a_{j},b_{j}<=1000$ ) — the color and diameter of the $j$ -th cap, correspondingly.
Next $n$ lines describe the markers. The $i$ -th line contains two space-separated integers $x_{i}$ , $y_{i}$ ( $1<=x_{i},y_{i}<=1000$ ) — the $i$ -th marker's color and diameter, correspondingly.
Next $m$ lines describe the caps. The $j$ -th line contains two space-separated integers $a_{j}$ , $b_{j}$ ( $1<=a_{j},b_{j}<=1000$ ) — the color and diameter of the $j$ -th cap, correspondingly.
输出格式
Print two space-separated integers $u,v$ , where $u$ is the number of closed markers and $v$ is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
输入输出样例
输入 #1
3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2
输出 #1
3 2
输入 #2
2 2 1 2 2 1 3 4 5 1
输出 #2
1 0
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted