Nikanor Loves Games
Time limit1sMemory limit512 MB
Choose positive integers a and b for one coin, paying a*b, to maximize expected winnings across n friends whose two-sided coins are known, where ties go to Nikanor.
- Level
Hard8 of 10
- Topics
- Math, Geometry, Sorting, Brute force
- Solved
- No attempts yet
Problem
Nikanor spends all his free time on games. Because of this, he gets bad marks at the university, but that's another story. He also likes gambling. In this problem, we consider the modification of the game called "Orlyanka". There are two players, and each of them has his own coin. Each of the two sides of a coin contains an integer. Players toss their coins, and the winner is the one with the highest number. We can assume that for each coin the probabilities of coming up both sides are equal.
Tonight Nikanor is playing this game with his friends. Nikanor has friends, and he will play with each of them for a bet of rubles. Fortunately, Nikanor knows that his -th friend has a coin with the numbers and . If Nikanor wins against his friend, he will receive rubles. Otherwise, he will pay rubles to his friend. If Nikanor and his friend dropped the same value, Nikanor is declared the winner.
Now Nikanor is going to go to the store and buy one coin for all games to maximize his expected profit, taking the coin cost into account. In this shop, a coin with the numbers and costs rubles. Nikanor can buy any coin with positive integers.
It's so hard for Nikanor to make the right decision... Nikanor asks you to help him choose a coin so that the expected profit is as high as possible.
Input
The first line contains one integer () denoting the number of friends.
Each of the following lines contains three integers , , and () representing the numbers on -th friend's coin and -th bet in rubles.
Output
Print a single integer --- the maximum expected profit.
Your answer will be considered correct if its absolute or relative error does not exceed .
Formally, let your answer be , and the jury's answer be . Your answer will be accepted if and only if .