E. Santa Claus and Tangerines
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Santa Claus has n tangerines, and the i-th of them consists of exactly ai 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 bi be the number of slices the i-th pupil has in the end. Let Santa's joy be the minimum among all bi's.

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

Input

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 a1, a2, ..., an (1 ≤ ai ≤ 107), where ai stands for the number of slices the i-th tangerine consists of.

Output

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.

Examples
input
3 2
5 9 3
output
5
input
2 4
12 14
output
6
input
2 3
1 1
output
-1
Note

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 5slices 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 7slices.

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

思路:二分+dp;复杂度(1e7*log(1e7));

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e6+,M=1e7+,inf=1e9+;
const ll INF=1e18+,mod=;
int a[N],n;
ll k;
ll dp[M];
int main()
{
scanf("%d%lld",&n,&k);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
int st=;
int en=1e7;
int ans=-;
while(st<=en)
{
int mid=(st+en)>>;
//cout<<mid<<endl;
ll sum=;
for(int i=; i<mid; i++)
dp[i]=;
for(int i=mid; i<=; i++)
{
dp[i]=;
dp[i]=max(dp[i],dp[i/]+dp[i-i/]);
}
for(int i=; i<=n; i++)
sum+=dp[a[i]];
if(sum>=k)
{
ans=mid;
st=mid+;
}
else
en=mid-;
}
printf("%d\n",ans);
return ;
}

Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines的更多相关文章

  1. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  2. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!

    A. Santa Claus and a Place in a Class 模拟题.(0:12) 题意:n列桌子,每列m张桌子,每张桌子一分为2,具体格式看题面描述.给出n,m及k.求编号为k的桌子在 ...

  6. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  7. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  8. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. l创建Excel文件

    最近的项目中遇到需要将List<Map<String,String>>存储到Excel文件中,为满足此需求设计实现了如下函数: /** * 将MapList转化为Excel文件 ...

  2. C#、不说再见

    公司技术转型,.NET To Java,以后逐渐踏入Java阵营. 再见了 Java嫌弃的老同学,再见了 来不及说出的谢谢 再见了 不会再有的.NET,再见了 我留给你毕业册的最后一页 我相信 我们还 ...

  3. XPath 简介

    XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 在学习之前应该具备的知识: 在您继续学习之前,应该对下面的知识有基本的了解: HTML ...

  4. c++ DLL->DEF->LIB

    一.DLL->DEF https://support.microsoft.com/zh-cn/kb/177429 https://msdn.microsoft.com/zh-cn/library ...

  5. 解读ContentResolver和ContentProvider

    转自:http://cthhqu.blog.51cto.com/7598297/1281217 1. ContentProvider的概述 ContentProvider: (Official Def ...

  6. linux 配置 ftp

    1.检测是否安装ftp 2.apt-get install 安装 (如果安装失败 执行apt-get install update<如果update失败 配置dns让自己的服务器 可以ping ...

  7. 夺命雷公狗-----React---26--小案例之react经典案例todos(统计部分的完成)

    这一个其实是比较容易的,只需要统计他的总数和已完成的即可, 效果如下所示: 代码如下所示: <!DOCTYPE html> <html lang="en"> ...

  8. <connectionStrings> <appSettings> 读取方法

    C#中ConnectionStrings和AppSettings的区别 时间 2013-03-07 15:57:00  博客园精华区 原文  http://www.cnblogs.com/bindot ...

  9. oracle性能优化之表设计

    数据库优化的目标无非是避免磁盘I/O瓶颈.减少CPU利用率和减少资源竞争.为了便于读者阅读和理解,笔者参阅了Sybase.Informix和Oracle等大型数据库系统参考资料,基于多年的工程实践经验 ...

  10. XML Schema choice 元素

    XSD : <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://w ...