Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)
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)的更多相关文章
- 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 ...
- Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)
https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...
- 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) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- 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> ...
- 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 ...
- Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix
https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...
- 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 ...
- Codeforces Round #540 (Div. 3)题解
题目链接: https://codeforces.com/contest/1118 A题: 题意: q次查询,给你一个n,要你用1和2来凑出n,1的花费为a,2的花费为b,求花费的最小值. 思路: 我 ...
随机推荐
- python 网络基础 之 网络协议
osi 七层协议 互联网协议按照功能不同分为osi七层或者tcp/ip 五层或tcp/ip 四层 tcp/ip 四层 1.应用层 2.传输层 3.网络层 4.网络接口层 tcp/ip 五层 1.应用层 ...
- swoole的EventLoop学习
我们先使用php来写一个socket的服务端.先从最开始的模型开始将起逐步引申到为何要使用eventloop 1.最简单的socket服务端,直接按照官方文档来执行 <?php $sock = ...
- 放大Button热区的方法哟
//添加图片不能用backgroundimage [btn setImage:image5 forState:]; //然后 btn.imageEdgeInsets = UIEdgeInsetsMak ...
- Centos查公网IP地址
[root@syy ~]# curl icanhazip.com 115.29.208.111
- POJ 3169.Layout 最短路
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11612 Accepted: 5550 Descripti ...
- MySQL连接、登录、密码等
官方教程:https://dev.mysql.com/doc/refman/8.0/en/ 链接数据库,通过指定 -h 参数可以连接网络上的数据库 mysql -u 用户名 -h 服务器IP -P 端 ...
- DB2 OLAP函数的使用
说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...
- java中HashMap的基本方法使用
遍历,添加词,等等 package test; import java.util.HashMap; import java.util.Iterator; import java.util.ArrayL ...
- 前端之javascript的DOM对象和标签
一 DOM对象介绍 什么是HTML DOM 1.1 HTML Document Object Model(文档对象模型) 1.2 HTML DOM 定义了访问和操作HTML文档的标准方法. 1.3 H ...
- python使用Fabric模块实现自动化运维
简介:Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:命令执行.文件上传.下载及完整 ...