Codeforces - 1118D2 - Coffee and Coursework (Hard Version) - 二分
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) - 二分的更多相关文章
- Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)
https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...
- 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)\)的贡献,问最 ...
- 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 ...
- Coffee and Coursework (Hard Version)
Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...
- Coffee and Coursework (Easy version)
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)
https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...
- 【Codeforces 1118D1】Coffee and Coursework (Easy version)
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中. a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分 ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- Codeforces 749D:Leaving Auction(set+二分)
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...
随机推荐
- vue - 前置工作
vue 中文官网:https://cn.vuejs.org/ vue ES6语法:https://www.cnblogs.com/zhouyangla/p/7225335.html vue Debug ...
- Python——正則表達式(2)
本文译自官方文档:Regular Expression HOWTO 參考文章:Python--正則表達式(1) 全文下载 :Python正則表達式基础 ======================== ...
- [LightOJ 1018]Brush (IV)[状压DP]
题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...
- Pycharm下运行程序查看每个变量的值的方法(类似于Spyder和MATLAB)
昨天,用了大量篇幅讲了Spyder的各种问题,之所以要用Spyder,最重要的一个原因就是能够非常方便的查看中间变量的值.类似MATLAB的工作空间,非常方便.如下图所示: 但是Spyder的代码自动 ...
- 在HDInsight中的Hadoop介绍
在HDInsight中的Hadoop介绍 概览 Azure的HDInsight是,部署和规定的Apache™Hadoop®集群在云中,提供用于管理,分析和大数据报告软件框架中的服务. 大数据 数据被描 ...
- 基础才是重中之重~用好configSections让配置信息更规范
对于小型项目来说,配置信息可以通过appSettings进行配置,而如果配置信息太多,appSettings显得有些乱,而且在开发人员调用时,也不够友好,节点名称很容易写错,这时,我们有几种解决方案 ...
- js modify local file
https://stackoverflow.com/questions/4561157/is-it-possible-to-modify-a-html-file-from-which-the-scri ...
- spark mongo 性能优化
性能优化事项 http://www.mongoing.com/wp-content/uploads/2016/08/MDBSH2016/TJ_MongoDB+Spark.pdf MongoDB + S ...
- mysql 数据库导入错误:40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RES ...
- Hadoop一些要注意的点
1.大多小文件的劣处: a. 生成更多的map任务,额外的开销: b. 每个文件都需要守址时间: c. HDFS上namenode需要占用内存空间: