CF1503C.Travelling Salesman Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn cities numbered from 11 to nn , and city ii has beauty aia_i .

A salesman wants to start at city 11 , visit every city exactly once, and return to city 11 .

For all iji\ne j , a flight from city ii to city jj costs max(ci,ajai)\max(c_i,a_j-a_i) dollars, where cic_i is the price floor enforced by city ii . Note that there is no absolute value. Find the minimum total cost for the salesman to complete his trip.

输入格式

The first line contains a single integer nn ( 2n1052\le n\le 10^5 ) — the number of cities.

The ii -th of the next nn lines contains two integers aia_i , cic_i ( 0ai,ci1090\le a_i,c_i\le 10^9 ) — the beauty and price floor of the ii -th city.

输出格式

Output a single integer — the minimum total cost.

输入输出样例

  • 输入#1

    3
    1 9
    2 1
    4 1

    输出#1

    11
  • 输入#2

    6
    4 2
    8 4
    3 0
    2 3
    7 1
    0 1

    输出#2

    13

说明/提示

In the first test case, we can travel in order 13211\to 3\to 2\to 1 .

  • The flight 131\to 3 costs max(c1,a3a1)=max(9,41)=9\max(c_1,a_3-a_1)=\max(9,4-1)=9 .
  • The flight 323\to 2 costs max(c3,a2a3)=max(1,24)=1\max(c_3, a_2-a_3)=\max(1,2-4)=1 .
  • The flight 212\to 1 costs max(c2,a1a2)=max(1,12)=1\max(c_2,a_1-a_2)=\max(1,1-2)=1 .

The total cost is 1111 , and we cannot do better.

首页