Oil
InterviewTime limit2sMemory limit1024 MB
Given dollars and euros and n countries that each sell oil for a fixed dollar price or a fixed euro price, find the maximum barrels buyable when each country must be paid in a single currency.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Math, Binary search
- Solved
- No attempts yet
Problem
The president of a small but very proud country has just learned that the twenty-first century is here and that riding horses is no longer fashionable. It turns out, however, that the country has no oil, and cars cannot run without gasoline. So oil will have to be bought from other countries.
A study of the foreign market showed that there are countries in the world that export oil. The -th state sells a barrel of oil either for dollars or for euros.
The president has dollars and euros. The chief accountant says that if one tries to buy oil from a single state with both dollars and euros, the bureaucracy may delay the purchase for a long time, which the president certainly does not want.
Help the president figure out, under these difficult conditions, how many barrels of oil he can buy.
Input
The first line of the input file contains three integers: , , and (, ). The next lines contain pairs of numbers , ().
Output
Print the maximum amount of oil the president can buy. Print the answer with at least two digits after the decimal point.