Where's That Fuel?
InterviewTime limit2sMemory limit256 MB
Starting with planet P's fuel, repeatedly visit affordable planets to maximize final fuel, then the number of visits.
Problem
Team Star Fox collects fuel from N planets. Planet i has Ai fuel cells, and travelling there from anywhere costs Bi fuel. Each planet yields fuel only once. Starting at planet P, they collect its fuel immediately, then may visit other planets in any order while fuel never goes negative. Maximize final fuel, then maximize planets visited among optimal tours.
Input
The first line has N and P. The next N lines contain Ai and Bi.
Output
Print the maximum fuel on the first line and the maximum number of visited planets on the second.