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
  1. 3 2
    5 9 3
Output
  1. 5
Input
  1. 2 4
    12 14
Output
  1. 6
Input
  1. 2 3
    1 1
Output
  1. -1
  2.  
  3. 题意:n个橘子分给m个人,没个橘子有num[i]瓣,求获得最少的人最多获得多少瓣
    题解:当num[i]的和小于m,输出-1.
    否则,维护最大的答案,每次将最大的橘子分成两瓣,更新最大答案,不可分则退出
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. using namespace std;
  5. #define maxn 10000010
  6. #define CLR(a,b) memset(a,b,sizeof(a))
  7. long long num[maxn];
  8. int main()
  9. {
  10. int n,m;
  11. long long sum=;
  12. scanf("%d %d",&n,&m);
  13. for(int i=;i<=n;i++){
  14. int x;
  15. scanf("%d",&x);
  16. num[x]++;
  17. sum+=x;
  18. }
  19.  
  20. if(sum < m){
  21. printf("-1\n");
  22. return ;
  23. }
  24.  
  25. sum = ;
  26. int left=;
  27. for(int i=maxn;i>;i--){
  28. sum+=num[i];
  29. if(sum>=m){ //如果橘子数量大于m个小朋友,则最小的橘子为最小答案
  30. left=i;
  31. break;
  32. }
  33. }
  34. for(int i=maxn;i>;i--){
  35. if(i/<left)
  36. break;
  37. num[i/]+=num[i];
  38. num[i-i/]+=num[i];
  39. sum+=num[i]; //sum[i]已经包含一个num[i],+num[i]相当于分成两瓣
  40. num[i]=;
  41. while(sum-num[left]>=m){
  42. sum-=num[left];
  43. left++;
  44. }
  45. }
  46.  
  47. printf("%d\n",left);
  48.  
  49. return ;
  50. }
  1.  

CodeForces - 748E (枚举+脑洞)的更多相关文章

  1. Codeforces 1154G 枚举

    题意:给你一堆数,问其中lcm最小的一对数是什么? 思路:因为lcm(a, b) = a * b / gcd(a, b), 所以我们可以考虑暴力枚举gcd, 然后只找最小的a和b,去更新答案即可. 数 ...

  2. codeforces 873E(枚举+rmq)

    题意 有n(n<=3000)个人参与acm比赛,每个人都有一个解题数,现在要决定拿金牌的人数cnt1,拿银牌的人数cnt2,拿铜牌的人数cnt3,各自对应一个解题数区间[d1,c1],[d2,c ...

  3. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  4. Codeforces 1216E2 枚举位数+二分

    两个二分 枚举位数 #include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long lo ...

  5. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces 965 枚举轮数贪心分糖果 青蛙跳石头最大流=最小割思想 trie启发式合并

    A /*#include<cstring>#include<algorithm>#include<queue>#include<vector>#incl ...

  7. CodeForces - 748E Santa Claus and Tangerines(二分)

    题意:将n个蛋糕分给k个人,要保证每个人都有蛋糕或蛋糕块,蛋糕可切, 1.若蛋糕值为偶数,那一次可切成对等的两块. 2.若蛋糕值为奇数,则切成的两块蛋糕其中一个比另一个蛋糕值多1. 3.若蛋糕值为1, ...

  8. Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)

    题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...

  9. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

随机推荐

  1. linux下chmod使用

    用法 chmod使用语法 $ chmod [options] mode[,mode] file1 [file2 ...] 使用ls命令的查看文件或目录的属性 $ ls -l file 八进制语法 ch ...

  2. Vue加载组件、动态加载组件的几种方式

    https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...

  3. sql中索引不会被用到的几种情况

    1.查询谓词没有使用索引的主要边界,换句话说就是select *,可能会导致不走索引. 比如,你查询的是SELECT * FROM T WHERE Y=XXX;假如你的T表上有一个包含Y值的组合索引, ...

  4. Mac下必备快捷键的符号所对应的按键

    Mac下快捷键的符号所对应的按键 ⌥—> option|alt ⇧—>shift ⌃—>control ⌘—>command ⎋—>esc 注: 与F6/F7/F12等F ...

  5. Innotop的安装和使用

    功能特点1.显示当前innodb的全部事务列表:2.显示当前正运行着的查询:3.显示当前锁和锁等等的列表:4.服务器状态和变量的摘要信息 显示了数值的相对变化幅度:5.有多种模式可用来显示Innodb ...

  6. mysql常用的一些修改命令

    修改表字段名称: alter table  table_name change column column_name_old  column_name_new column_type; mysql注释 ...

  7. How can R and Hadoop be used together?

    Referer: http://www.quora.com/How-can-R-and-Hadoop-be-used-together/answer/Jay-Kreps?srid=OVd9&s ...

  8. JAVA 线程池架构浅析

    经历了Java内存模型.JUC基础之AQS.CAS.Lock.并发工具类.并发容器.阻塞队列.atomic类后,我们开始JUC的最后一部分:线程池.在这个部分你将了解到下面几个部分: 线程池的基础架构 ...

  9. 【Spark 深入学习 01】 Spark是什么鬼?

    经过一段时间的学习和测试,是时候给spark的学习经历做一个总结了,对于spark的了解相对晚了写.春节期间(预计是无大事),本博准备推出20篇左右spark系列原创文章(先把牛吹出去再说) ,尽量将 ...

  10. github desktop的使用

    1.建仓库 2.添加文件 3.提交文件到本地仓库 4.撤销提交到本地仓库 或者直接Ctrl+Z 5.提交到远端仓库 6.添加一个分支 7.分支合并 1.本地仓库合并 将新分支添加的文件合并到maste ...