luogu#P4088. [USACO18FEB] Slingshot P
[USACO18FEB] Slingshot P
题目描述
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with an intriguing idea: instead of hauling manure between two points in a cart behind his tractor, why not shoot it through the air with a giant manure slingshot? (indeed, what could possibly go wrong...) Farmer John's farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). FJ builds slingshots (), where the th slingshot is described by three integers , , and , specifying that this slingshot can shoot manure from position to position in only total units of time.
FJ has piles of manure to transport (). The th such pile needs to be moved from position to position . Hauling manure with the tractor for a distance of takes units of time. FJ is hoping to reduce this by allowing up to one use of any slingshot for transporting each pile of manure. Time FJ spends moving his tractor without manure in it does not count.
For each of the manure piles, please help FJ determine the minimum possible transportation time, given that FJ can use up to one slingshot during the process.
输入格式
The first line of input contains and . The next lines each describe a single slingshot in terms of integers , , and (). The final lines describe piles of manure that need to be moved, in terms of integers and .
输出格式
Print lines of output, one for each manure pile, indicating the minimum time needed to transport it.
题目大意
Farmer John最讨厌的农活是运输牛粪。为了精简这个过程,他产生了一个新奇的想法:与其使用拖拉机拖着装满牛粪的大车从一个地点到另一个地点,为什么不用一个巨大的便便弹弓把牛粪直接发射过去呢?(事实上,好像哪里不太对……) Farmer John的农场沿着一条长直道路而建,所以他农场上的每个地点都可以简单地用该地点在道路上的位置来表示(相当于数轴上的一个点)。FJ建造了个弹弓(),其中第个弹弓可以用三个整数,以及描述,表示这个弹弓可以在单位时间内将牛粪从位置发射到位置。
FJ有堆牛粪需要运输()。第堆牛粪需要从位置移动到位置。使用拖拉机运输牛粪,经过路程需要消耗单位时间。FJ希望通过对每一堆牛粪使用至多一次弹弓来减少运输时间。FJ驾驶没有装载牛粪的拖拉机的时间不计。
对这堆牛粪的每一堆,在FJ可以在运输过程中使用至多一次弹弓的条件下,帮助FJ求出其最小运输时间。
输入格式(文件名:slingshot.in): 输入的第一行包含和。下面行,每行用,,()描述了一个弹弓。最后行用和描述了需要移动的牛粪。
输出格式(文件名:slingshot.out): 输出行,每堆牛粪一行,表示运输这堆牛粪需要的最短时间。
2 3
0 10 1
13 8 2
1 12
5 2
20 7
4
3
10
提示
Here, the first pile of manure needs to move from position 1 to position 12. Without using an slingshot, this would take 11 units of time. However, using the first slingshot, it takes 1 unit of time to move to position 0 (the slingshot source), 1 unit of time to fling the manure through the air to land at position 10 (the slingshot destination), and then 2 units of time to move the manure to position 12. The second pile of manure is best moved without any slingshot, and the third pile of manure should be moved using the second slingshot.
Problem credits: Brian Dean