Discount Optimisation

Time limit: 0.4s Memory limit: 64MB Input: Output:

Tommaso has just happened to know of a massive discount campaign in a supermarket in his neighbourhood. Being notoriously greedy, he is now planning to take the most advantage out of it!

The supermarket is selling NN unique items, each marked with a distinct identifier ii from 00 to N1N − 1. Every item has a full price PiP_i, a discounted price SiS_i, and an attached promotional code RiR_i. Once a buyer has to pay for her shopping cart, she will qualify for the discounted price for a bought item ii if and only if she has at least one matching promotional code attached to some item(s) in her shopping cart. Otherwise, she will have to pay the full price.

Notice that if item 00 gives a promotional code for item 11, and vice-versa item 11 provides a code for item 00, it is possible to buy items 00 and 11 both at their discounted prices. On the other hand, it is impossible to buy multiple copies of the same item, and having several promotional codes for a single item does not increase the discount. It is however possible for an item to provide a promotional code for itself, so that it is never paid full price.

Tommaso is willing to buy just about anything from the supermarket, in order to boast the highest possible discount percentage. Assume that Tommaso chooses to buy a certain subset of the items, whose total full price is Ptot, for which he pays an actual price of Pdiscount using promotional codes. Then the discount percentage for those items is computed as:

100(1PdiscountPtot)100 \cdot (1 - \frac{P_{discount}}{P_{tot}})

Help Tommaso find the best possible bargain!

Input data

The first line contains the only integer NN. The following NN lines each contain the three integers PiP_i, SiS_i and RiR_i for item ii.

Output data

You need to write a single line with a floating-point number: the best percentage of discount Tommaso can obtain.

Constraints and clarifications

  • 1N100 0001 \leq N \leq 100 \ 000;
  • 1Si<Pi10 0001 \leq S_i < P_i \leq 10 \ 000;
  • 0Ri<N0 \leq R_i < N;
  • Your program will be tested against several test cases grouped in subtasks. In order to obtain the score of a subtask, your program needs to correctly solve all of its test cases. You answer is considered correct if it is within 10610^{−6} of the correct value.
# Score Constraints
1 0 Examples
2 10 Ri=iR_i = i for all ii
3 15 N20N \leq 20
4 20 N1 000N \leq 1 \ 000
5 20 RiiR_i \leq i for all ii
6 25 R0=N1R_0 = N-1 and Ri=i1R_i = i-1 for all i>0i > 0
7 10 No additional limitations.

Example 1

stdin

6
100 90 1
10 9 2
90 20 5
100 80 2
40 30 3
100 10 3

stdout

80.000000000

Explanation

In the first sample case the best solution is to buy items 11, 22 and 55 spending P1P_1 + S2S_2 + S5S_5 = 4040 instead of P1P_1 + P2P_2 + P5P_5 = 200200. The discount percentage is 100(140200)=80%100 \cdot \left(1 - \frac{40}{200}\right) = 80\% This is because item 11’s promotional code enables the discount of item 22, and the code of item 22 enables the discount of item 55.

Example 2

stdin

5
100 70 1
10 3 2
11 3 3
12 3 1
10 9 4

stdout

72.727272727

Explanation

In the second sample case the best solution is to buy items 11, 22 and 33 spending S1S_1 + S2S_2 + S3S_3 = 99 instead of P1P_1 + P2P_2 + P3P_3 = 3333. The discount percentage is 100(1933)=72.7272727%100 \cdot \left(1 - \frac{9}{33}\right) = 72.7272727\%. The three items enable the discount for each other, therefore all of them are paid with the sale price.

Log in or sign up to be able to send submissions!