Need For Speed
InterviewTime limit1sMemory limit128 MB
Given a car's base force and mass plus N parts that each add force and mass, choose the subset maximizing total force over total mass, breaking ties by smaller total mass.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Implementation, Brute force
- Solved
- No attempts yet
Problem
Bessie is tuning her race car for the upcoming Grand Prix and wants to buy extra parts to make it faster.
Right now the car has mass () and can push itself forward with force (). By Newton's second law , so its acceleration is .
The parts store sells () parts numbered through , with at most one of each in stock. Buying part adds force () and mass (). Bessie may buy any subset of the parts, including none of them.
If Bessie installs the parts in a set , the car's total force becomes and its total mass becomes , giving acceleration
Choose the set of parts that maximizes this acceleration. If several sets achieve the same maximum acceleration, choose the one with the smallest total mass. The optimal set is guaranteed to be unique.
For example, installing a single part with force and mass changes the acceleration to .
Input
The first line contains three space-separated integers , , and .
Each of the next lines contains two space-separated integers: line holds and , the force and mass added by part .
Output
Print the 1-based indices of the parts Bessie should install, in increasing order, one per line. If installing no part is optimal, print NONE.