CF1060D Social Circles

    • 187通过
    • 293提交
  • 题目来源 CodeForces 1060D
  • 评测方式 RemoteJudge
  • 标签 排序 贪心
  • 难度 省选/NOI-
  • 时空限制 2000ms / 512MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    现在有$N$个人,每一个人都不想周围的人坐得离他很近,所以在他的左边要放$L_i$张椅子,右边要放$R_i$张椅子.

    现在他们要坐成若干个圈,请问最少要放多少张椅子.

    注意:可以一个人坐在一个圈内.每一个人还需要坐一张椅子.

    题目描述

    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?

    输入输出格式

    输入格式:

    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 $ ).

    输出格式:

    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.

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。