Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) D. Social Circles 【贪心】

本文探讨了如何在安排晚宴时,根据每位宾客所需的左右空位数量,最小化所需椅子总数的问题。通过分析宾客需求并使用排序算法,确定了最优布局方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D. Social Circles

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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 lili free chairs to the left of his chair, and at least riri 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 lili chairs to his left and riri chairs to his right may overlap.

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

Input

First line contains one integer nn  — number of guests, (1⩽n⩽1051⩽n⩽105).

Next nn lines contain nn pairs of space-separated integers lili and riri (0⩽li,ri⩽1090⩽li,ri⩽109).

Output

Output a single integer — the smallest number of chairs you have to use.

Examples

input

Copy

3
1 1
1 1
1 1

output

Copy

6

input

Copy

4
1 2
2 1
3 5
5 3

output

Copy

15

input

Copy

1
5 6

output

Copy

7

Note

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.

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 2e6 + 3;
int a[MAX], b[MAX];

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d%d", &a[i], &b[i]);
    }
    sort(a, a + n);
    sort(b, b + n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += max(a[i], b[i]) + 1;
    }
    printf("%lld", ans);
    return 0;
}

 

内容概要:论文提出了一种基于空间调制的能量高效分子通信方案(SM-MC),将传输符号分为空间符号和浓度符号。空间符号通过激活单个发射纳米机器人的索引来传输信息,浓度符号则采用传统的浓度移位键控(CSK)调制。相比现有的MIMO分子通信方案,SM-MC避免了链路间干扰,降低了检测复杂度并提高了性能。论文分析了SM-MC及其特例SSK-MC的符号错误率(SER),并通过仿真验证了其性能优于传统的MIMO-MC和SISO-MC方案。此外,论文还探讨了分子通信领域的挑战、优势及相关研究工作,强调了空间维度作为新的信息自由度的重要性,并提出了未来的研究方向和技术挑战。 适合人群:具备一定通信理论基础,特别是对纳米通信和分子通信感兴趣的科研人员、研究生和工程师。 使用场景及目标:①理解分子通信中空间调制的工作原理及其优势;②掌握SM-MC系统的具体实现细节,包括发射、接收、检测算法及性能分析;③对比不同分子通信方案(如MIMO-MC、SISO-MC、SSK-MC)的性能差异;④探索分子通信在纳米网络中的应用前景。 其他说明:论文不仅提供了详细的理论分析和仿真验证,还给出了具体的代码实现,帮助读者更好地理解和复现实验结果。此外,论文还讨论了分子通信领域的标准化进展,以及未来可能的研究方向,如混合调制方案、自适应调制技术和纳米机器协作协议等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值