Renting Bikes 二分
来源:互联网 发布:查看端口占用 编辑:程序博客网 时间:2024/05/22 01:47
做了两次还是错 我宛如一个智障
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.
The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs pj rubles.
In total, the boys’ shared budget is a rubles. Besides, each of them has his own personal money, the i-th boy has bi personal rubles. The shared budget can be spent on any schoolchildren arbitrarily, but each boy’s personal money can be spent on renting only this boy’s bike.
Each boy can rent at most one bike, one cannot give his bike to somebody else.
What maximum number of schoolboys will be able to ride bikes? What minimum sum of personal money will they have to spend in total to let as many schoolchildren ride bikes as possible?
Input
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 105; 0 ≤ a ≤ 109). The second line contains the sequence of integers b1, b2, …, bn (1 ≤ bi ≤ 104), where bi is the amount of the i-th boy’s personal money. The third line contains the sequence of integers p1, p2, …, pm (1 ≤ pj ≤ 109), where pj is the price for renting the j-th bike.
Output
Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0.
求最大租车数
先把车子和小孩都按从小都大排列,那么就有单调性,二分枚举租车数。判断条件为从最有钱的孩子还是减去,m开始的最贵的车。逆推就好
#include <bits/stdc++.h>using namespace std;int a[101010];int b[101010];int main(){ int n,m,t; scanf("%d%d%d",&n,&m,&t); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<m;i++) scanf("%d",&b[i]); sort(a,a+n); sort(b,b+m); int l=0; int r=min(n,m); int ans=0; long long sum=0; while(l<=r) { sum=0; int mid=(l+r)>>1; for(int i=0;i<mid;i++) if(b[mid-i-1]>a[n-i-1]) sum+=b[mid-i-1]-a[n-i-1]; if(sum<=t) { ans=mid; l=mid+1; } else r=mid-1; } long long ssum=0; for(int i=0;i<ans;i++) { ssum+=b[ans-i-1]; } ssum=max(0LL,ssum-t); printf("%d %lld\n",ans,ssum );}
- Renting Bikes 二分
- Renting Bikes(二分+贪心)
- cf#211-D. Renting Bikes-二分
- codeforces363D——Renting Bikes(二分,贪心)
- CodeForces 363D.Renting Bikes(二分+贪心)
- Codeforces 363D Renting Bikes【二分+贪心】
- CF 363D. Renting Bikes 贪心+二分
- Renting Bikes
- Renting Bikes
- CodeForces 363D Renting Bikes (二分+贪心)
- D. Renting Bikes(CodeFroce)
- Code forces363D Renting Bikes
- Renting Bikes CodeForces
- CodeForces 363D - Renting Bikes
- CodeForces 363D Renting Bikes
- Codeforces 363D Renting Bikes
- Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!
- Codeforces Round #211 (Div. 2)D. Renting Bikes(二分,想法题,好题)
- 百度富文本编辑器的上传图片的路径问题
- CUDA之Dynamic Parallelism详解(二)
- zoomeye用户使用手册
- css Sprite
- nodejs:使用emailjs发送邮件
- Renting Bikes 二分
- eclipse 使用maven 构建springboot+注入servlet
- 1. thinkphp相关
- source 命令找不到的情况(修改完/etc/profile文件之后,使其生效)
- OPENGL编程练习
- Linux权限的简单用法(使用者、文件、目录)
- Linux shell编程之输入输出重定向上篇
- iOS开发-三种倒计时的写法
- JSP页面编码设置