#P15069. [UOI 2024 II Stage] Disco

    ID: 16998 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学二分2024Special Judge分数规划UOI(乌克兰)

[UOI 2024 II Stage] Disco

题目描述

Anton, as a teacher at school, is organizing a disco for the children. He has been tasked with selecting a playlist so that everyone is thrilled with the celebration. But Anton has a huge database of songs, and unfortunately, the time for the disco is limited :(.

Specifically, there are nn songs in the database. Each song can be characterized by two integers tit_i and rir_i --- the length of the song and its rating. As a music lover, Anton wants to select exactly\textbf{exactly} kk songs (i.e., not fewer) to maximize the ratio of the sum of ratings to the sum of lengths.

More formally, let SS be the set of songs and XSX \subseteq S, X=k|X|=k --- a subset of songs that have been selected for the playlist. The goal is to maximize $\displaystyle \frac{\sum_{i \in X} r_i}{\sum_{i \in X} t_i}$. In other words, it is necessary to find the sum of the numbers rir_i of all the songs that will be played at the disco, find the sum of the numbers tit_i of all the songs that will be played at the disco, and divide the former by the latter. This number needs to be maximized.

Find and output the maximum possible ratio.

输入格式

The first line contains two integers nn, kk (1kn1051 \le k \le n \le 10^5) --- the total number of songs and the number of songs to be selected for the playlist.

The second line contains nn integers rir_i (1ri1051 \le r_i \le 10^5).

The third line contains nn integers tit_i (1ti1051 \le t_i \le 10^5).

输出格式

Output a single number --- the maximum ratio.

Your answer will be considered correct if its absolute or relative error does not exceed 10410^{-4}.

Formally, let your answer be aa, and the jury's answer be bb. Your answer will be accepted if and only if abmax(1,b)104\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}.

2 2
1 2
2 3
0.600000
5 2
1 2 3 2 3
2 4 2 5 3
1.200000

提示

In the first example, there are two songs that need to be added to the playlist. Therefore, the ratio will be:

1+22+3=35=0.6\frac{1+2}{2+3}=\frac{3}{5}=0.6

In the second example, it is best to take the third and fifth songs. Therefore, the ratio will be:

3+32+3=65=1.2\frac{3+3}{2+3}=\frac{6}{5}=1.2