当前位置:网站首页>D - Project Planning--二分
D - Project Planning--二分
2022-08-03 21:03:00 【秦小咩】
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400400 points
Problem Statement
KEYENCE has NN departments, where A_iAi employees belong to the ii-th department (1 \leq i \leq N)(1≤i≤N). No employee belongs to multiple departments.
The company is planning cross-departmental projects. Each project will be composed of exactly KK employees chosen from KK distinct departments.
At most how many projects can be made? No employee can participate in multiple projects.
Constraints
- 1 \leq K \leq N \leq 2 \times 10^51≤K≤N≤2×105
- 1 \leq A_i \leq 10^{12}1≤Ai≤1012
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN KK A_1A1 A_2A2 \ldots… A_NAN
Output
Print the maximum possible number of projects.
Sample Input 1 Copy
Copy
3 3 2 3 4
Sample Output 1 Copy
Copy
2
There can be two projects, each composed of three employees from distinct departments.
Sample Input 2 Copy
Copy
4 2 1 1 3 4
Sample Output 2 Copy
Copy
4
Sample Input 3 Copy
Copy
4 3 1 1 3 4
Sample Output 3 Copy
Copy
2
=========================================================================
数据范围小的话优先队列贪心是很容易理解的。但本题需要二分,或许用到的这个结论是很普遍,需要特殊记住的计数问题,那就是n个小组,每组k个物体,要求组内不能重复,那么最终判定条件是所有小于等于n(大于n取等于n)的个数要 >= n*k,也就是说,只要数量够了,一定能构造出来不重复n个序列,很不好想或者去证明,只能说是一个计数结论罢了

注意r太大会爆掉,故我们取r=1e18/k,再乘k的时候就不会爆掉了,当然128位也是很方便。
题目没一般说明我们都是在1e18内获取答案的
# include <iostream>
# include<vector>
# include<queue>
# include<map>
# include<vector>
# include<algorithm>
# include<cstring>
# include<iomanip>
# include<set>
# include<math.h>
using namespace std;
typedef __int128 ll;
__int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
void print(__int128 x){
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar(x%10+'0');
}
ll a[200000+10];
ll k,n;
bool check(ll mid)
{
ll sum=0;
for(int i=1;i<=n;i++)
{
sum+=min(mid,a[i]);
}
return mid*k<=sum;
}
int main()
{
n=read();
k=read();
for(int i=1;i<=n;i++)
{
a[i]=read();
}
ll l=1,r=1e18;
while(l<=r)
{
ll mid=(l+r)>>1;
if(check(mid))
l=mid+1;
else
r=mid-1;
}
print(r);
return 0;
}
边栏推荐
- Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation
- leetcode 125. 验证回文串
- ES、Kibana 8.0安装
- Leetcode 16. Numerical integral power (power + fast recursive/iteration)
- error: C1083: 无法打开包括文件: “QString”: No such error: ‘QDir‘ file not found
- 云图说丨初识华为云微服务引擎CSE
- 服务器安装redis
- win10安装及配置Gradle
- 基于data.table的tidyverse?
- 剑指 Offer 07. 重建二叉树
猜你喜欢

StoneDB 助力 2022 开放原子全球开源峰会

《富爸爸,穷爸爸》思维导图和学习笔记

error: C1083: 无法打开包括文件: “QString”: No such error: ‘QDir‘ file not found

李沐动手学深度学习V2-BERT微调和代码实现

Power button - 203 - remove the list elements linked list

云图说丨初识华为云微服务引擎CSE
![[kali-vulnerability scanning] (2.1) Nessus download and installation (on)](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[kali-vulnerability scanning] (2.1) Nessus download and installation (on)

From September 1st, my country has granted zero-tariff treatment to 98% of tax items from 16 countries including Togo

开源一夏 |如何优化线上服务器

Several difficult problems in DDD
随机推荐
leetcode 16.01. 交换数字(不使用临时变量交换2个数的值)
迪赛智慧数——柱状图(多色柱状图):2021年我国城市住户存款排名
tidyverse based on data.table?
用 setTimeout 来实现 setInterval
肝完 Alibaba 这份面试通关宝典,我成功拿下今年第 15 个 Offer
[kali-vulnerability scanning] (2.1) Nessus download and installation (on)
华为设备配置VRRP与BFD联动实现快速切换
如何使用 Jmeter获取登录token并设置为全局变量?
在树莓派上搭建属于自己的网页(4)
if _name_ == “__main__“:NameError: name ‘_name_‘ is not defined
buildscript和allprojects的作用和区别是什么?
这几个常用 alias,带你高效做事(下)
LitJson报错记录
XSS测试
太香了! 阿里 Redis 速成笔记, 从头到尾全是精华!
模板字符串
ES6 deconstruction assignment - array object deconstruction and deconstruction
3种圆形按钮悬浮和点击事件
Interesting opencv - record image binarization and similarity
dataframe 多层索引 更换索引 df.swaplevel(axis=1)