QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#2859. Freshman Dance Party

统计

The school is organizing a freshman dance party, and Cathy, an experienced senior, is responsible for pairing up the students. There are $n$ boys and $n$ girls participating in the party. Each boy and each girl will be paired together to dance.

Cathy has collected information about the relationships between these students. For example, she knows whether two people are already acquainted, and she has calculated $a_{i,j}$, which represents the level of enjoyment when the $i$-th boy and the $j$-th girl dance together.

Cathy also needs to consider the convenience of the two people dancing together, such as whether their heights are too different. She has calculated $b_{i,j}$, which represents the degree of awkwardness when the $i$-th boy and the $j$-th girl dance together.

Of course, there are many other factors to consider. Cathy wants to use a program to find a pairing scheme based on $a_{i,j}$ and $b_{i,j}$, and then fine-tune the scheme manually.

In a given scheme with $n$ pairs, suppose the enjoyment level of each pair is $a'_1, a'_2, \dots, a'_n$, and the awkwardness level of each pair is $b'_1, b'_2, \dots, b'_n$. Let:

$$C = \frac{a'_1 + a'_2 + \dots + a'_n}{b'_1 + b'_2 + \dots + b'_n}$$

Cathy wants to maximize $C$.

Input

The first line contains an integer $n$. The next $n$ lines each contain $n$ integers, where the $j$-th integer in the $i$-th line represents $a_{i,j}$. The next $n$ lines each contain $n$ integers, where the $j$-th integer in the $i$-th line represents $b_{i,j}$.

Output

Output a single number representing the maximum value of $C$. The result should be rounded to 6 decimal places, and the output must match the standard answer.

Constraints

  • For 10% of the data: $1 \le n \le 5$
  • For 40% of the data: $1 \le n \le 18$
  • For an additional 20% of the data: $b_{i,j} = 1$
  • For 100% of the data: $1 \le n \le 100$, $1 \le a_{i,j} \le 10^4$, $1 \le b_{i,j} \le 10^4$

Examples

Input 1

3
19 17 16
25 24 23
35 36 31
9 5 6
3 4 2
7 8 9

Output 1

5.357143

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.