CF1060D.Social Circles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You invited nn 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 ii -th guest wants to have a least lil_i free chairs to the left of his chair, and at least rir_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 lil_i chairs to his left and rir_i chairs to his right may overlap.

What is smallest total number of chairs you have to use?

输入格式

First line contains one integer nn — number of guests, ( 1n1051 \leqslant n \leqslant 10^5 ).

Next nn lines contain nn pairs of space-separated integers lil_i and rir_i ( 0li,ri1090 \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 55 chairs accomodating guests 11 and 22 , and another one with 1010 chairs accomodationg guests 33 and 44 .

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.

首页