#abc275g. G - Infinite Knapsack

G - Infinite Knapsack

Score : 600600 points

问题描述

NN 种类型的物品,每种物品都有无限多个复制品。第 ii 种物品的重量为 AiA_i,体积为 BiB_i,价值为 CiC_i

等级为 XX 的高桥最多能携带总重量不超过 XX、总体积也不超过 XX 的物品。在此条件下,他可以携带任意数量的同种物品,也可以选择不携带某些种类的物品。

f(X)f(X) 表示等级为 XX 的高桥能够携带的最大物品总价值。可以证明极限 limXf(X)X\displaystyle\lim_{X\to \infty} \frac{f(X)}{X} 存在。求这个极限值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN kinds of items, each with infinitely many copies. The ii-th kind of item has a weight of AiA_i, a volume of BiB_i, and a value of CiC_i.

Level XX Takahashi can carry items whose total weight is at most XX and whose total volume is at most XX. Under this condition, it is allowed to carry any number of items of the same kind, or omit some kinds of items.

Let f(X)f(X) be the maximum total value of items Level XX Takahashi can carry. It can be proved that the limit limXf(X)X\displaystyle\lim_{X\to \infty} \frac{f(X)}{X} exists. Find this limit.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 108Ai,Bi,Ci10910^8\leq A_i,B_i,C_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1 C1C_1

A2A_2 B2B_2 C2C_2

\vdots

ANA_N BNB_N CNC_N

Output

Print the answer. Your output will be considered correct if the absolute or relative error from the judge's answer is at most 10610^{-6}.

Sample Input 1

2
100000000 200000000 100000000
200000000 100000000 100000000

Sample Output 1

0.6666666666666667

When X=300000000X=300000000, Takahashi can carry items whose total weight is at most 300000000300000000 and whose total volume is at most 300000000300000000.

He can carry, for instance, one copy of the 11-st item and one copy of the 22-nd item. Then, the total value of the items is 100000000+100000000=200000000100000000+100000000=200000000. This is the maximum achievable value, so f(300000000)300000000=23\dfrac{f(300000000)}{300000000}=\dfrac{2}{3}.

It can also be proved that limXf(X)X\displaystyle\lim_{X\to \infty} \frac{f(X)}{X} equals 23\dfrac{2}{3}. Thus, the answer is 0.6666666...0.6666666....

Sample Input 2

1
500000000 300000000 123456789

Sample Output 2

0.2469135780000000

update @ 2024/3/10 11:35:50