A12096 | Social Circles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You invited $n$ guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles.
Your guests happen to be a little bit shy, so the $i$ -th guest wants to have a least $l_i$ free chairs to the left of his chair, and at least $r_i$ free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the $l_i$ chairs to his left and $r_i$ chairs to his right may overlap.
What is smallest total number of chairs you have to use?
Your guests happen to be a little bit shy, so the $i$ -th guest wants to have a least $l_i$ free chairs to the left of his chair, and at least $r_i$ free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the $l_i$ chairs to his left and $r_i$ chairs to his right may overlap.
What is smallest total number of chairs you have to use?
输入格式
First line contains one integer $n$ — number of guests, ( $1 \leqslant n \leqslant 10^5$ ).
Next $n$ lines contain $n$ pairs of space-separated integers $l_i$ and $r_i$ ( $0 \leqslant l_i, r_i \leqslant 10^9$ ).
Next $n$ lines contain $n$ pairs of space-separated integers $l_i$ and $r_i$ ( $0 \leqslant l_i, r_i \leqslant 10^9$ ).
输出格式
Output a single integer — the smallest number of chairs you have to use.
输入输出样例
输入 #1
3 1 1 1 1 1 1
输出 #1
6
输入 #2
4 1 2 2 1 3 5 5 3
输出 #2
15
输入 #3
1 5 6
输出 #3
7
In the second sample the only optimal answer is to use two circles: a circle with $5$ chairs accomodating guests $1$ and $2$ , and another one with $10$ chairs accomodationg guests $3$ and $4$ .
In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.
In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted