問題一覧 > 通常問題

No.472 Average Rank

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 256 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-5}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 180
作問者 : roiti46 / テスター : ぴろず
お気に入りにしたユーザー ProblemId : 734 / 自分の提出
問題文最終更新日: 2026-06-25 13:35:05
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Advent Calendar Contest 2016 (順位表) の他の問題:

Note

This problem was created as the problem for day 22 of Advent Calendar Contest Advent Calendar 2016.

It has been confirmed that AC is possible with C++ and PyPy2, but Python gets TLE.
The writer's solution submitted in PyPy2 gets AC in about 1200 ms.

Problem Statement

Yuki loves a quiz-solving contest called "Surume Four Seas" and takes part in it every time without fail.
Each contest has 3 quiz questions, and the rank is determined by the number of questions solved (submission speed does not matter).
In other words, solving all 3 questions always gives a tie for 1st place.

One day, the organizers' database was lost, and the only data remaining were the rank for solving n (0 ≤ n ≤ 3) questions in each contest,
and the total number of questions each user has solved during contests so far.

Yuki wanted to know her average rank, but that is no longer possible.
For now, she decided to take the minimum possible average rank as her average rank.

On behalf of the busy Yuki, find the minimum value of her average rank.

Note that in each contest, there exists at least one user who solved 0 questions, at least one who solved 1 question, at least one who solved 2 questions, and at least one who solved 3 questions.

Input

$N$ $P$
$a_0$ $b_0$ $c_0$
$a_1$ $b_1$ $c_1$
.
.
.
$a_{N-1}$ $b_{N-1}$ $c_{N-1}$

$N$: the number of contests
$P$: the number of questions Yuki solved during contests
$a_k$ $b_k$ $c_k$: the ranks when solving 0, 1, and 2 questions, respectively, in the $k$-th contest (solving 3 questions always gives 1st place)

All input satisfies the following constraints.
$1 \leq N \leq 5000$
$0 \leq P \leq 3N$
$100000 \geq a_k \gt b_k \gt c_k \gt 1$

Output

Output the minimum value of Yuki's average rank.
A relative or absolute error of at most $10^{-5}$ in the output is allowed.

Sample

Sample 1
Input
2 2
100 50 10
999 990 4
Output
52.0

If she solved 0 questions in the first contest for 100th place,
and 2 questions in the second contest for 4th place,
the average rank is 52, which is the minimum.

Sample 2
Input
2 2
200 50 4
115 70 5
Output
59.5

If she solved 2 questions in the first contest for 4th place,
and 0 questions in the second contest for 115th place,
the average rank is 59.5, which is the minimum.

Sample 3
Input
2 0
332 33 2
114 51 4
Output
223.0

It seems Yuki is not good at quizzes.

Sample 4
Input
3 9
123 45 6
789 12 3
456 78 9
Output
1.0

It seems Yuki is a quiz pro.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。