eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Best Coalitions

Best Coalitions

Envy Inc. is a joint stock company, that is, a company in which every stockholder legally owns shares of stock that account for some percentage of the total shares of stock of the company. Due to the global economic crisis, the management rules of Envy Inc. define a particular way for distributing last year's profit: if a stockholder owns more than half of the shares of stock, he/she wins the total profit. Nothing fancy so far in this wild world! Nevertheless, there are situations in which no stockholder owns more than \textbf{50}\% of the shares of stock of the company. So, in order to gain some profit, stockholders are allowed to form \textit{coalitions}, i.e., groups of stockholders. The participation of the coalition, share-wise, is equivalent to the sum of its stockholders' percentile participation. Hence, if a coalition has more than half of the shares of stock, its members win the totality of last years profit. Then, the members of the coalition receive a part of the profit proportional to their individual participation in the coalition. For instance, let us assume there are \textbf{5} stockholders: \textbf{A}, \textbf{B}, \textbf{C}, \textbf{D} and \textbf{E}, owning \textbf{20}\%, \textbf{12}\%, \textbf{14}\%, \textbf{29}\% and \textbf{25}\% of the stock of the company, respectively. The stockholder \textbf{E} could form several winning coalitions. For example, if \textbf{E} were to form a coalition with \textbf{A} and \textbf{B}, he/she would get \textbf{43.86}\% of last year's profit. If \textbf{E} were to form a coalition with \textbf{B} and \textbf{C} instead, he/she would get \textbf{49.02}\% of last year's profit. On the other hand, \textbf{E} could not form a winning coalition with only \textbf{A}. Your problem is, given a distribution of shares of stock of Envy Inc., and a stockholder, to determine the maximum percentage of the last year's profit that the given stockholder may win. \InputFile The input consists of several test cases, each one defining a percentile distribution of shares of stock, and the index of a stockholder to determine his/her optimal participation. More precisely, each test case is defined by several input lines: \begin{itemize} \item the first line contains two integer values \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100}) and \textbf{x} (\textbf{1} ≤ \textit{\textbf{x}} ≤ \textbf{n}), separated by a blank, representing the number of stockholders in Envy Inc. and the index of a stockholder to determine his/her optimal participation, respectively; \item each one of the following \textbf{n} lines has a single floating point value \textbf{p_i}, rounded to \textbf{2} decimal places, which represents the percentage of stock ownership of stockholder \textbf{i} (\textbf{1} ≤ \textbf{i} ≤ \textbf{n}). The floating point delimiter is "\textbf{.}" (i.e. the dot). You can assume that \textbf{p_1} + ... + \textbf{p_n} = \textbf{100}. \end{itemize} The end of the input is indicated by \textbf{n} = \textbf{x} = \textbf{0}, an artificial case that must be ignored. \OutputFile For each given case, output a single line with the corresponding answer. The answer should be formatted and approximated to two decimal places. The floating point delimiter must be "\textbf{.}" (i.e. the dot). The rounding applies towards the nearest neighbor unless both neighbors are equidistant, in which case the result is rounded up (e.g. \textbf{78.312} is rounded to \textbf{78.31}; \textbf{78.566} is rounded to \textbf{78.57}; \textbf{78.345} is rounded to \textbf{78.35}, etc.).
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
5 5
20.00
12.00
29.00
14.00
25.00
2 1
56.87
43.13
2 2
56.87
43.13
3 1
10.00
45.00
45.00
0 0
Вихідні дані #1
49.02
100.00
43.13
18.18