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

和easy version的主要区别是,数据增加了。

easy version采用的是线性查找,效率低

在这里采用binary search就可以了

#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> num;
int C(int d){
int sum=;
for(int i=;i<n;i++){
sum+=max(num[i]-i/d,);
if(sum>=m)
return ;
}
return ;
}
int main(){
cin>>n>>m;
num.resize(n);
for(int i=;i<n;i++){
cin>>num[i];
}
sort(num.rbegin(),num.rend());
int l=,r=n;
while(r-l>){
int mid=(l+r)>>;
if(C(mid))
r=mid;
else
l=mid;
}
if (C(l)) cout << l << endl;
else if (C(r)) cout << r << endl;
else cout << - << endl;
return ;
}

Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)的更多相关文章

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

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

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

  3. 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)\)的贡献,问最 ...

  4. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  5. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  6. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  7. Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix

    https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...

  8. Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)

    https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...

  9. Codeforces Round #540 (Div. 3)题解

    题目链接: https://codeforces.com/contest/1118 A题: 题意: q次查询,给你一个n,要你用1和2来凑出n,1的花费为a,2的花费为b,求花费的最小值. 思路: 我 ...

随机推荐

  1. 1.git使用入门之基本的更新提交操作

    在项目开发中使用git的规范,避免因为不规范的操作带来额外的工作量 更行代码 git pull 提交代码 .查看状态 git status .添加到本地缓存 git add .(所有,也可以单个添加) ...

  2. 浏览器与服务器交互原理以及用java模拟浏览器操作v

    浏览器应用服务器JavaPHPApache * 1,在HTTP的WEB应用中, 应用客户端和服务器之间的状态是通过Session来维持的, 而Session的本质就是Cookie, * 简单的讲,当浏 ...

  3. LED

    LED 时间限制: 1 Sec  内存限制: 128 MB 题目描述 数字显示器题目描述:最近学校晚上文化广场的人很多哇,原因是晚上大屏幕会放电影.无聊的艾神和x73也决定一起去文化大广场看一场电影, ...

  4. iOS.CocoaPods.0

    1. CocoaPods CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器. A CocoaPod (singular) is a speci ...

  5. Win10传递优化设置技巧

    什么是“传递优化缓存” “传递优化”是微软为了加快Windows更新和Microsoft Store应用更新的下载速度,而在Windows10中引入的一种“自组织分布式本地化缓存”设计,可以在用户电脑 ...

  6. BZOJ1178或洛谷3626 [APIO2009]会议中心

    BZOJ原题链接 洛谷原题链接 第一个问题是经典的最多不相交区间问题,用贪心即可解决. 主要问题是第二个,求最小字典序的方案. 我们可以尝试从\(1\to n\)扫一遍所有区间,按顺序对每一个不会使答 ...

  7. VirtualBox安装android-x86-4.4-r2

    https://jingyan.baidu.com/album/a681b0de1373133b184346cf.html?picindex=10

  8. .net委托

    今天要学的是委托 委托的基本形式 直接上代码 public delegate int AddDelegate(int x,int y); class Program { static void Mai ...

  9. 通过修改Delphi 的 RTL,加快Delphi开发的应用程序速度和稳定性

    RT 具体见PDF 看了不后悔,只给高手准备的. 神呐,偶看看是虾米东东

  10. idea15 生成mybatis代码

    pom.xml <build> <finalName>mybatis_generator</finalName> <plugins> <plugi ...