102756: [AtCoder]ABC275 G - Infinite Knapsack

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

There are $N$ kinds of items, each with infinitely many copies. The $i$-th kind of item has a weight of $A_i$, a volume of $B_i$, and a value of $C_i$.

Level $X$ Takahashi can carry items whose total weight is at most $X$ and whose total volume is at most $X$. 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)$ be the maximum total value of items Level $X$ Takahashi can carry. It can be proved that the limit $\displaystyle\lim_{X\to \infty} \frac{f(X)}{X}$ exists. Find this limit.

Constraints

  • $1\leq N\leq 2\times 10^5$
  • $10^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:

$N$
$A_1$ $B_1$ $C_1$
$A_2$ $B_2$ $C_2$
$\vdots$
$A_N$ $B_N$ $C_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 $10^{-6}$.


Sample Input 1

2
100000000 200000000 100000000
200000000 100000000 100000000

Sample Output 1

0.6666666666666667

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

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

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


Sample Input 2

1
500000000 300000000 123456789

Sample Output 2

0.2469135780000000

Input

题意翻译

小 T 在玩游戏,目前他的等级是 $x$。 游戏中有 $n$ 个物品,每个物品的有三个属性 $(a,b,v)$,每个物品有无限个。 根据开发者设定,等级为 $x$ 的人买的物品的 $a$ 的和与 $b$ 的和都必须小于等于 $x$。 设 $f(x)$ 为等级为 $x$ 的人能买到的最大价值。求 $\lim_{x \to +\infty} \frac{f(x)}{x}$ 的值。能够证明,极限存在。

Output

分数:600分

问题描述

有N种物品,每种都有无限多的复制品。第i种物品的重量为A_i,体积为B_i,价值为C_i。

级别为X的高桥可以携带总重量不超过X且总体积不超过X的物品。在这种条件下,允许携带相同种类的任意数量的物品,或者省略某些种类的物品。

令f(X)为级别为X的高桥可以携带的物品的总价值的最大值。可以证明,极限$\displaystyle\lim_{X\to \infty} \frac{f(X)}{X}$存在。找出这个极限。

限制条件

  • $1\leq N\leq 2\times 10^5$
  • $10^8\leq A_i,B_i,C_i \leq 10^9$
  • 输入中的所有值都是整数。

输入

输入将从标准输入以以下格式给出:

$N$
$A_1$ $B_1$ $C_1$
$A_2$ $B_2$ $C_2$
$\vdots$
$A_N$ $B_N$ $C_N$

输出

打印答案。如果您的输出与裁判答案的绝对误差或相对误差不超过$10^{-6}$,则将被视为正确。


样例输入1

2
100000000 200000000 100000000
200000000 100000000 100000000

样例输出1

0.6666666666666667

当$X=300000000$时,高桥可以携带总重量不超过$300000000$且总体积不超过$300000000$的物品。

例如,他可以携带第1种物品的一份复制品和第2种物品的一份复制品。那么,物品的总价值为$100000000+100000000=200000000$。这是可以达到的最大值,因此$\dfrac{f(300000000)}{300000000}=\dfrac{2}{3}$。

还可以证明$\displaystyle\lim_{X\to \infty} \frac{f(X)}{X}$等于$\dfrac{2}{3}$。因此,答案为$0.6666666...$。


样例输入2

1
500000000 300000000 123456789

样例输出2

0.2469135780000000

加入题单

算法标签: