CF1060D.Social Circles
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 li free chairs to the left of his chair, and at least ri 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 li chairs to his left and ri chairs to his right may overlap.
What is smallest total number of chairs you have to use?
你邀请了 n 位客人共进晚餐!你计划布置一个或多个圆形椅子排列。每把椅子要么坐一位客人,要么为空。你可以布置任意数量的圆圈。
你的客人恰好有点害羞,因此第 i 位客人希望其椅子左侧至少有 li 个空椅子,右侧至少有 ri 个空椅子。“左”和“右”的方向是基于所有客人均朝向圆心就座这一假设来确定的。注意:当某位客人是其所处圆圈中唯一一人时,其左侧的 li 把空椅子与右侧的 ri 把空椅子可能重叠。
你最少需要准备多少把椅子?
输入格式
First line contains one integer n — number of guests, (1⩽n⩽105).
Next n lines contain n pairs of space-separated integers li and ri (0⩽li,ri⩽109).
第一行包含一个整数 n —— 客人的数量(1⩽n⩽105)。
接下来的 n 行,每行包含一对由空格分隔的整数 li 和 ri(0⩽li,ri⩽109)。
输出格式
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.
在第二个样例中,唯一的最优方案是使用两个圆圈:一个包含 5 把椅子的圆圈容纳客人 1 和 2,另一个包含 10 把椅子的圆圈容纳客人 3 和 4。
在第三个样例中,你只有一个圆圈,且圆圈中仅有一名客人。该客人左侧至少需要有 5 把空椅子,右侧(到下一位客人,即她本人)至少需要有 6 把空椅子。因此,椅子总数至少为 6+1=7。
输入解题思路,AI测评打分。不知道怎么写?