Maximize the Acceleration
InterviewTime limit1sMemory limit128 MB
Given N parts that each add force and mass, choose the subset maximizing total force divided by total mass, breaking ties by smaller mass.
- Level
Medium4 of 10
- Topics
- Brute force, Bit manipulation, Greedy, Math
- Solved
- No attempts yet
Problem
Bessie is tuning her race car for an upcoming Grand Prix. Right now the car has mass and pushes itself forward with force . A performance shop sells upgrade parts numbered through . The shop stocks at most one of each part, so Bessie may install any subset of the parts (possibly none).
Installing part adds force and mass to the car. By Newton's second law , the car's acceleration equals its total force divided by its total mass. If Bessie installs a set of parts, the acceleration becomes
For example, adding a single part with force and mass to a car with and raises the acceleration from to .
Bessie wants to pick the set of parts that maximizes the acceleration. If several different sets reach the same maximum acceleration, she prefers the set with the smallest total mass. Under these two rules the best set of parts is unique.
Constraints
Input
The first line contains three space-separated integers , , and .
Each of the next lines contains two space-separated integers and : the force and mass added by part .
Output
Print the indices of the parts Bessie should install, one per line, in increasing order. If she should install no parts at all, print NONE.