CF1503C.Travelling Salesman Problem

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 i≠ji\ne j, a flight from city ii to city jj costs max⁡(ci,aj−ai)\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.

有 nn 座城市,编号从 11 到 nn,其中城市 ii 的美丽值为 aia_i。

一名推销员希望从城市 11 出发,恰好访问每座城市一次,并最终返回城市 11。

对于所有 i≠ji \ne j,从城市 ii 飞往城市 jj 的航班费用为 max⁡(ci,aj−ai)\max(c_i, a_j - a_i) 美元,其中 cic_i 是城市 ii 规定的价格下限。注意:此处没有绝对值。求推销员完成该环游的最小总费用。

输入格式

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

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

第一行包含一个整数 nn(2≤n≤1052\le n\le 10^5)—— 城市的数量。

接下来的 nn 行中,第 ii 行包含两个整数 aia_i、cic_i(0≤ai,ci≤1090\le a_i,c_i\le 10^9)—— 第 ii 个城市的美丽值和价格下限。

输出格式

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 1→3→2→11\to 3\to 2\to 1.

  • The flight 1→31\to 3 costs max⁡(c1,a3−a1)=max⁡(9,4−1)=9\max(c_1,a_3-a_1)=\max(9,4-1)=9.
  • The flight 3→23\to 2 costs max⁡(c3,a2−a3)=max⁡(1,2−4)=1\max(c_3, a_2-a_3)=\max(1,2-4)=1.
  • The flight 2→12\to 1 costs max⁡(c2,a1−a2)=max⁡(1,1−2)=1\max(c_2,a_1-a_2)=\max(1,1-2)=1.

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

在第一个测试用例中,我们可以按顺序 1→3→2→11\to 3\to 2\to 1 进行旅行。

  • 航班 1→31\to 3 的费用为 max⁡(c1,a3−a1)=max⁡(9,4−1)=9\max(c_1,a_3-a_1)=\max(9,4-1)=9。
  • 航班 3→23\to 2 的费用为 max⁡(c3,a2−a3)=max⁡(1,2−4)=1\max(c_3, a_2-a_3)=\max(1,2-4)=1。
  • 航班 2→12\to 1 的费用为 max⁡(c2,a1−a2)=max⁡(1,1−2)=1\max(c_2,a_1-a_2)=\max(1,1-2)=1。

总费用为 1111,且无法得到更优解。

输入解题思路,AI测评打分。不知道怎么写?

首页