#P8209. [THUPC 2022 初赛] 赛程制定

[THUPC 2022 初赛] 赛程制定

Problem Description

Lewis loves boxing, so he founded a boxing club and hoped to raise money for his training by selling tickets for exhibition matches. Unfortunately, Lewis is not very popular, so the club has only two members—Lewis and his close friend Valtteri. The audience soon got tired of seeing only the two of them every night, tickets stopped selling, and the club was on the verge of bankruptcy. When things get tough, you look for changes, so Lewis decided to try to save his club by inviting guest fighters.

With enough money, Lewis quickly invited two boxing stars—Max and Checo—as special guests to join the club. In the next season, Lewis will arrange a total of nn (1n2105)(1 \le n \le 2*10^5) matches. Each match selects 2 out of the 4 current members to fight. For the ii-th (1in)(1 \le i \le n) match:

  • If it is a match between Lewis and Valtteri, it can sell tickets worth aia_i yuan.
  • If it is a match between one of them and a star, it can sell tickets worth bib_i yuan.
  • If it is a match between the two stars Max and Checo, it can sell tickets worth cic_i yuan.

The audience likes high-level matches between stars, not the weak fights between Lewis and Valtteri, so 1ai<bi<ci1091 \le a_i < b_i < c_i \le 10^9.

In addition, the following requirements must be satisfied when scheduling the matches:

  1. Since the stars are very busy, they only agree to stay in Lewis’s club for at most tm,tct_m, t_c matches, respectively. Let Max’s first attended match be match pmp_m and his last be match qmq_m, and Checo’s first attended match be match pcp_c and his last be match qcq_c. Then we must have qmpm+1tmq_m - p_m + 1 \le t_m and qcpc+1tcq_c - p_c + 1 \le t_c.
  2. Lewis knows he is no match for the two stars, and he does not want to be beaten up and knocked out, so he will not schedule any match between himself and either star. (In other words, the job of getting beaten is secretly assigned by Lewis to his close friend Valtteri. Let us mourn for the poor “tool person” Valtteri.)
  3. Lewis wants to maximize his total income, but he is not very smart. So, if a plan satisfies the following condition, he believes it achieves “maximum income”.

Definition (“Lewis’s optimal plan”): A plan can be viewed as a sequence of length 2n2n, where the (2i1)(2i-1)-th and 2i2i-th elements are the two fighters in match ii. If, by changing any one position of the sequence, it is impossible to obtain a legal plan whose income is strictly greater than the current income, then this plan is called “Lewis’s optimal plan”.

You quickly notice that “Lewis’s optimal plan” does not necessarily maximize the total income and may not be unique. It is known that Lewis will choose uniformly at random from all “Lewis’s optimal plans”. (Two plans are the same if and only if the matchups on every day are the same. Note that Max vs Valtteri and Checo vs Valtteri sell the same tickets, but they are considered two different plans.) Then, among all plans that Lewis may finally choose, what is the median of the ticket income? (Output the answer rounded to one decimal place.)

Input Format

Line 11: Three positive integers n,tm,tcn, t_m, t_c, as defined in the statement.

Next nn lines: Each line contains three positive integers ai,bi,cia_i, b_i, c_i, representing the ticket price in the three cases.

Output Format

Output one number in one line, representing the median of the ticket income among all plans that Lewis may finally choose.

2 1 1
1 10 100
1 2 3
12.0
3 1 3
1 2 3
5 6 12
1 5 6
14.0

Hint

[Sample Explanation]

Lewis’s “maximum income plan” has the following 44 possibilities:

  • Max vs Checo, Lewis vs Valtteri, ticket income is 100+1=101100+1=101.
  • Valtteri vs Max, Valtteri vs Checo, ticket income is 10+2=1210+2=12.
  • Valtteri vs Checo, Valtteri vs Max, ticket income is 10+2=1210+2=12.
  • Lewis vs Valterri, Max vs Checo, ticket income is 1+3=41+3=4.

The median is 12+122=12\frac{12+12}{2} = 12.

[Constraints]

For 100%100\% of the testdata, 1n,tm,tc21051 \le n, t_m, t_c \le 2*10^5, and 1ai<bi<ci1091 \le a_i < b_i < c_i \le 10^9.

Translated by ChatGPT 5