Ito
Time limit1sMemory limit512 MB
Each valuable's next-year price is uniform between a and b, and each client wants the maximum expected money while keeping at least l in the worst case.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Sorting
- Solved
- No attempts yet
Problem
Math can be very interesting and fascinating, and it is no doubt worth a lifetime. But if you plan to spend your last days somewhere in the Caribbean, feeling warm sand under your feet and watching beautiful women bring you pina coladas one by one, you should find another use for your skills.
So Kiyoshi decided that his contribution to math was already great enough, and he would go make some money. As you have probably heard, an economic crisis is approaching quickly, and everyone wants an efficient way to save money. To follow the new market trends, Kiyoshi opened a consulting agency that helps clients invest their savings properly. Investment here has three simple steps: go to the market and buy some valuables, wait a year, then go back to the market and sell them.
There are different valuables available for investment. For each one, the current price wooddollars per measure unit is given. All valuables are unlimited in quantity and arbitrarily divisible, so you may buy any non-negative real amount of any valuable. For each valuable, two limits and are known. Next year, the cost of one measure unit will be continuously and uniformly distributed between these two values.
clients want Kiyoshi to create a good investment plan for each of them. The -th client has wooddollars. On one hand, each client wants to maximize the expected amount of money they will have after selling all valuables. On the other hand, they fear losing too much, so they want at least wooddollars in the worst case.
For each client, Kiyoshi needs to choose how much of each valuable the client should buy. The client can spend any amount of wooddollars, but no more than they own. Any unspent money is kept until next year. Tell each client the maximum expected sum of wooddollars they could have without risking too much.
Input
The first line contains two integers and (), the number of valuables and the number of clients.
The next lines describe the valuables. Each contains three integers , , and : the current cost of the valuable, and the limits and on its future cost (, ).
Then lines describe the clients. Each contains two integers and : the amount of money the client has, and the minimum amount the client accepts in the worst case ().
Output
Print lines. The -th line contains one real number: the maximum expected amount of wooddollars the -th client could have without risking too much. An answer is accepted if its absolute or relative error does not exceed . Formally, if your answer is and the jury's answer is , the checker accepts it when .
Hint
In the example above, the first client buys units of the second valuable and units of the third. The second client buys units of the first valuable, units of the second, and units of the third. The third client buys just unit of the second valuable.