CF1503C.Travelling Salesman Problem
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities numbered from 1 to n, and city i has beauty ai.
A salesman wants to start at city 1, visit every city exactly once, and return to city 1.
For all i=j, a flight from city i to city j costs max(ci,aj−ai) dollars, where ci is the price floor enforced by city i. Note that there is no absolute value. Find the minimum total cost for the salesman to complete his trip.
有 n 座城市,编号从 1 到 n,其中城市 i 的美丽值为 ai。
一名推销员希望从城市 1 出发,恰好访问每座城市一次,并最终返回城市 1。
对于所有 i=j,从城市 i 飞往城市 j 的航班费用为 max(ci,aj−ai) 美元,其中 ci 是城市 i 规定的价格下限。注意:此处没有绝对值。求推销员完成该环游的最小总费用。
输入格式
The first line contains a single integer n (2≤n≤105) — the number of cities.
The i-th of the next n lines contains two integers ai, ci (0≤ai,ci≤109) — the beauty and price floor of the i-th city.
第一行包含一个整数 n(2≤n≤105)—— 城市的数量。
接下来的 n 行中,第 i 行包含两个整数 ai、ci(0≤ai,ci≤109)—— 第 i 个城市的美丽值和价格下限。
输出格式
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→1.
- The flight 1→3 costs max(c1,a3−a1)=max(9,4−1)=9.
- The flight 3→2 costs max(c3,a2−a3)=max(1,2−4)=1.
- The flight 2→1 costs max(c2,a1−a2)=max(1,1−2)=1.
The total cost is 11, and we cannot do better.
在第一个测试用例中,我们可以按顺序 1→3→2→1 进行旅行。
- 航班 1→3 的费用为 max(c1,a3−a1)=max(9,4−1)=9。
- 航班 3→2 的费用为 max(c3,a2−a3)=max(1,2−4)=1。
- 航班 2→1 的费用为 max(c2,a1−a2)=max(1,1−2)=1。
总费用为 11,且无法得到更优解。
输入解题思路,AI测评打分。不知道怎么写?