当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5303:Delicious Apples

题目描述
There are $n$ apple trees planted along a cyclic road, which is $L$ metres long. Your storehouse is built at position $0$ on that cyclic road.
The $i$th tree is planted at position $x_i$, clockwise from position $0$. There are $a_i$ delicious apple(s) on the $i$th tree.

You only have a basket which can contain at most $K$ apple(s). You are to start from your storehouse, pick all the apples and carry them back to your storehouse using your basket. What is your minimum distance travelled?

$1\le n,k\le 10^5, a_i\ge 1, a_1+a_2+...+a_n\le 10^5$
$1\le L\le 10^9$
$0\le x[i]\le L$

There are less than 20 huge testcases, and less than 500 small testcases.
输入解释
First line: $t$, the number of testcases.
Then $t$ testcases follow. In each testcase:
First line contains three integers, $L,n,K$.
Next $n$ lines, each line contains $x_i,a_i$.
输出解释
Output total distance in a line for each testcase.
输入样例
2
10 3 2
2 2
8 2
5 1
10 4 1
2 2
8 2
5 1
0 10000
输出样例
18
26
来自杭电HDUOJ的附加信息
Author XJZX
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5303

最后修改于 2020-10-25T23:21:30+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/3000MS(Java/Others) 524288/524288K(Java/Others)