Canadian Computing Competition: 2014 Stage 2, Day 2, Problem 1
The heroic Team Star Fox is on a mission to collect as much fuel as possible from various planets across the Lylat System. There are planets, and the -th one contains fuel cells - but travelling there from any other planet uses up fuel cells . Unfortunately, fuel cells are not a sustainable resource, so if a planet is visited for a second time, there will be no new fuel to collect.
Team Star Fox starts on planet - as such, they may collect its fuel cells immediately. They may then travel to as many different planets as they'd like to, in any order, as long as they have sufficient fuel to spend on each flight (that is, their fuel cell count remains non-negative). Finally, they may choose to stop at any point (possibly even before leaving planet ), with the goal of maximizing the number of fuel cells they end up with. If this can be done in multiple ways, they'd like to maximize the number of different planets they visit as a secondary objective. Can you help our heroes?
The first line contains two integers: , followed by a space, followed by , which represents the number of planets followed by the starting planet number. The next lines contain , followed by a space, followed by .
You can assume that for test cases worth about 20% of the marks, .
The output consists of two lines, with each line containing one positive integer. The first line contains the largest number of fuel cells that Team Star Fox can possess once they decide to stop. The second line contains the largest number of planets that Team Star Fox can visit, such that they still end up with this maximal number of fuel cells.
5 2 12 12 10 100 8 3 4 5 25 15
Output for Sample Input
Explanation of Output for Sample Input
Team Star Fox starts on planet , on which they collect fuel cells to start off. They should proceed by travelling to planet , costing them fuel cells but then increasing their fuel cell count capacity to . Next, they can fly to planet , lowering their fuel cell count to but then promptly restoring it to . Finally, they have just enough fuel to reach planet , at which point they can collect its fuel cells to end up with . They should then choose to stop without ever visiting planet .