#P7700. [CCC 2014] 燃料搜集
[CCC 2014] 燃料搜集
Description
The brave Fox Star Squad is on a mission. Their task is to collect as much fuel as possible from different planets in the Layla galaxy. There are planets in the Layla galaxy. Planet contains units of fuel, but traveling to that planet from any planet costs units of fuel. Unfortunately, fuel is not a renewable resource, so if you visit a planet a second time, you will not collect any new fuel there.
The Fox Star Squad starts on planet , so they can immediately collect the fuel on that planet, and then they can begin the mission. As long as they have enough fuel (that is, after completing a flight, their remaining fuel is non-negative), they may visit planets in any order. In the end, they may stop on any planet, and they may even stop without ever leaving planet . Their goal is to maximize the total amount of fuel collected. If there are multiple ways to achieve this goal, they also want to maximize the number of distinct planets they have visited. Can you help them?
Input Format
The first line contains two integers separated by a space, representing the number of planets and the index of the starting planet.
The next lines each contain two integers .
Output Format
Output consists of two lines, each containing one positive integer.
The first line is the maximum total fuel the Fox Star Squad can collect when they stop.
The second line is the maximum number of distinct planets they can visit, under the condition that they collect the amount of fuel stated in the first line.
5 2
12 12
10 100
8 3
4 5
25 15
25
4
Hint
One optimal plan is: after collecting the fuel on planet (the starting planet), the Fox Star Squad departs from there and visits planets in order, collecting fuel on each. The travel costs along the way are respectively. Starting from the initial planet, the remaining fuel after collecting on each planet is . At this point, they should not go to planet , but should stop in order to maximize the total fuel collected at the end.
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号