https://codeforces.com/problemset/problem/1118/D2

也是很好想的一个二分啦。

验证m的可行性的时候,肯定是把最多咖啡因的咖啡先尽可能平均分到每一天,因为同一天内调换喝咖啡的顺序只会非增,而且平均分更优是显然的。

#include<bits/stdc++.h>
using namespace std;
#define ll long long int n,m;
int a[]; int ok(int mi){
ll sum=;
for(int i=;i<n;i++){
sum+=max(,a[i]-i/mi);
}
if(sum>=m)
return ;
else
return ;
} int binary(){
int l=,r=1e9,m;
while(){
m=(l+r)>>;
if(l==m){
if(ok(l)){
return l;
}
else if(ok(r)){
return r;
}
else{
return -;
}
}
if(ok(m)){
r=m;
}
else{
l=m+;
}
}
} int main(){
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n,greater<int>()); printf("%d\n",binary());
}

Codeforces - 1118D2 - Coffee and Coursework (Hard Version) - 二分的更多相关文章

  1. Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)

    https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...

  2. Codeforces Round #540 (Div. 3) D2. Coffee and Coursework (Hard Version) (二分,贪心)

    题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最 ...

  3. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  4. Coffee and Coursework (Hard Version)

    Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...

  5. Coffee and Coursework (Easy version)

    Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...

  6. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  7. 【Codeforces 1118D1】Coffee and Coursework (Easy version)

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中. a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分 ...

  8. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  9. Codeforces 749D:Leaving Auction(set+二分)

    http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...

随机推荐

  1. redis hash 类型的操作命令

    redis 文档: https://redis.readthedocs.io/en/2.4/index.html keys * type key --------------------------- ...

  2. mysql 同样内容的字段合并为一条的方法

    从两个表中内联取出的数据,当中category_name字段有同样内容,想将具有同样内容的字段进行合并,将amount字段进行加法运算,变成下表中的内容 url=http%3A%2F%2Fdev.my ...

  3. Bean property XX&#39; is not writable or has an invalid setter method

    刚刚搞spring.property注入时遇到这个问题,百度一下.非常多人说是命名或者get set方法不一致的问题,可是这个我是知道的.写的时候也注意到这些.所以应该不是这个问题.以为是xml头写的 ...

  4. cin,和几个get函数的用法

    1.cin.get(字符变量名):用来接收字符 ch = cin.get(); cin.get(ch); 以上两者均可以 2.cin.get(字符数组名,接收字符数目)用来接收一行字符串,可以接收空格 ...

  5. 编资源bundle时图片文件变成tiff的解决方法

    一般,编写SDK的时候,如果SDK还带了一些资源文件,那么最理想的是将资源文件也打包成为bundle给应用方一起使用.而在编资源bundle时,有时会发现编译好后的图片文件从png转成了tiff,这样 ...

  6. Python基础——数据类型、流程控制、常用函数

    Python tutorial :Python网站上的对 Python 语言和系统的基本概念和功能进行的非正式的介绍. 在学习Python之前,我们需要学会在各个平台配置Python的运行环境,下文中 ...

  7. VUE清除组件内部定时器

    定时器如果不手动清除,只会在离开当前页面或者F5刷新后才会清除.由于vue项目是SPA应用,离开当前组件后并不会清除定时器,所以需要我们手动去清除定时器.但当我们将清除定时器clearInterval ...

  8. attribute constructor&destructor

    attribute constructor&destructor 在看openwrt里libnl-tiny这个库的时候,遇到了C里面的构造函数这个概念. static void __init ...

  9. openwrt: patch-dtb

    dts的概念是linux kernel中的,跟openwrt的关系不大.只是恰好在学习openwrt的时候碰到了这个东西,所以记录在openwrt名下. patch-dtb openwrt对arch/ ...

  10. linux UDP,TCP相关特性

    好长时间没使用网络编程忘得差不多了,写了TCP,UDP测试代码,得出以下结论:   一:UDP特性 1. UDP sendto函数不管对端是否存在(即使对端原本存在,现在已经关闭了),都义无反顾的发送 ...