Delicious Apples

TimeLimit: 5000/3000 MS (Java/Others)  MemoryLimit: 524288/524288 K (Java/Others)
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
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 ith tree is planted at position x_i, clockwise from position 0. There are ai 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≤n,k≤105,ai≥1,a1+a2+...+an≤105
1≤L≤109
0≤x[i]≤L

There are less than 20 huge testcases, and less than 500 small testcases.
Input
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 xi,ai.
Output
Output total distance in a line for each testcase.
SampleInput
2
10 3 2
2 2
8 2
5 1
10 4 1
2 2
8 2
5 1
0 10000
SampleOutput
18
26
Submit
题目统计信息详细
总AC数2
通过人数2
尝试人数3
总提交量6
AC率33.33%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: