CF1060D.Social Circles
普及/提高-
通过率:0%
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?
输入格式
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 ).
输出格式
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.