CF748E.Santa Claus and Tangerines

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Santa Claus has n tangerines, and the i-th of them consists of exactly a__i slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines.

However, there can be too few tangerines to present at least one tangerine to each pupil. So Santa decided to divide tangerines into parts so that no one will be offended. In order to do this, he can divide a tangerine or any existing part into two smaller equal parts. If the number of slices in the part he wants to split is odd, then one of the resulting parts will have one slice more than the other. It's forbidden to divide a part consisting of only one slice.

Santa Claus wants to present to everyone either a whole tangerine or exactly one part of it (that also means that everyone must get a positive number of slices). One or several tangerines or their parts may stay with Santa.

Let b__i be the number of slices the i-th pupil has in the end. Let Santa's joy be the minimum among all b__i's.

Your task is to find the maximum possible joy Santa can have after he treats everyone with tangerines (or their parts).

圣诞老人有 nn 个橘子,其中第 ii 个橘子恰好由 aia_i 瓣组成。圣诞老人来到一所拥有 kk 名学生的学校,并决定用这些橘子来招待他们。

然而,橘子的总数可能不足以给每位学生至少一个完整的橘子。因此,圣诞老人决定将橘子切分成若干部分,以确保无人感到被冷落。为此,他可以将任意一个橘子或其任意现有部分均分为两个更小的相等部分;若待分割部分的瓣数为奇数,则分割后两部分的瓣数之差为 11(即一部分比另一部分多一瓣)。但禁止分割仅含一瓣的部分。

每位学生最终必须获得一个完整的橘子,或该橘子的恰好一个部分(这也意味着每位学生获得的瓣数必须为正整数)。一个或多个橘子(或其部分)可保留在圣诞老人处。

设 bib_i 表示第 ii 位学生最终获得的瓣数。圣诞老人的喜悦值定义为所有 bib_i 中的最小值。

你的任务是:求出在满足上述条件的前提下,圣诞老人所能达到的最大喜悦值。

输入格式

The first line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 2·109) denoting the number of tangerines and the number of pupils, respectively.

The second line consists of n positive integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 107), where a__i stands for the number of slices the i-th tangerine consists of.

第一行包含两个正整数 nn 和 kk(1 ≤ n ≤ 1061 \leq n \leq 10^6,1 ≤ k ≤ 2⋅1091 \leq k \leq 2\cdot10^9),分别表示橘子的数量和学生的数量。

第二行包含 nn 个正整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1 ≤ ai ≤ 1071 \leq a_i \leq 10^7),其中 aia_i 表示第 ii 个橘子所含的瓣数。

输出格式

If there's no way to present a tangerine or a part of tangerine to everyone, print -1. Otherwise, print the maximum possible joy that Santa can have.

如果无法将橘子或橘子的一部分分给每个人,请输出 -1。否则,请输出圣诞老人所能获得的最大快乐值。

输入输出样例

  • 输入#1

    3 2
    5 9 3

    输出#1

    5
  • 输入#2

    2 4
    12 14

    输出#2

    6
  • 输入#3

    2 3
    1 1

    输出#3

    -1

说明/提示

In the first example Santa should divide the second tangerine into two parts with 5 and 4 slices. After that he can present the part with 5 slices to the first pupil and the whole first tangerine (with 5 slices, too) to the second pupil.

In the second example Santa should divide both tangerines, so that he'll be able to present two parts with 6 slices and two parts with 7 slices.

In the third example Santa Claus can't present 2 slices to 3 pupils in such a way that everyone will have anything.

在第一个例子中,圣诞老人应将第二个橘子分成两部分,分别包含 5 片和 4 片。之后,他可以将含 5 片的那部分送给第一位学生,将整个第一个橘子(也含 5 片)送给第二位学生。

在第二个例子中,圣诞老人应将两个橘子都进行分割,从而能够送出两份各含 6 片的部分和两份各含 7 片的部分。

在第三个例子中,圣诞老人无法将 2 片橘子分给 3 名学生,使得每人都能分到至少一片。

输入解题思路,AI测评打分。不知道怎么写?

首页