Code forces363D Renting Bikes
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Sample Input
2 2 10
5 5
7 6
2 3
4 5 2
8 1 1 2
6 3 7 5 2
3 8
Hint
In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the
personal money. In total, they spend 3 rubles of their personal money. This way of distribution of money minimizes the amount of spent personal money.
#include<numeric>//STL数值算法头文件
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long LL;
const int N=1e5+10; LL a[N],b[N],w; int main()
{
int n,m;
while(~scanf("%d%d%lld",&n,&m,&w))
{
for(int i=1; i<=n; i++)
scanf("%lld",&a[i]);
for(int i=1; i<=m; i++)
scanf("%lld",&b[i]);
sort(a+1,a+n+1);
sort(b+1,b+m+1);
int ans=0,cas=100;
int left=0,right=min(n+1,m+1);
while(left<right&&cas--)
{
int mid=(left+right)/2;
LL res=0;
for(int i=1; i<=mid; i++)
{
if(a[n+1-i]<b[mid+1-i]) //最有钱的几个人去买最便宜的车以至于能买到最多数量的车;
res+=(b[mid+1-i]-a[n+1-i]);
}
if(res<=w)
{
left=mid;
ans=mid;
}
else
right=mid;
}
printf("%d",ans);
LL sum=0;
for(int i=1; i<=ans; i++)
{
if(a[n+1-i]<=b[ans+1-i])
{
sum+=a[n+1-i];
w-=(b[ans+1-i]-a[n+1-i]);
}
else
sum+=b[ans+1-i];
}
printf(" %lld\n",max(0LL,sum-w));//0LL表示把0转化为LL型,因为max函数要保持类型一致
}
return 0;
}
Code forces363D Renting Bikes的更多相关文章
- Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!
D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...
- cf D. Renting Bikes
http://codeforces.com/contest/363/problem/D 先对b和p排序,用二分求出可以租的车子的最大辆数,其中用mid以后的个人钱数去租前mid的价钱的车子. #inc ...
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 在Visual Studio Code中配置GO开发环境
一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
- http status code
属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...
随机推荐
- 不修改代码优化 ASP.NET 网站性能的一些方法
本文将介绍一些方法用于优化ASP.NET网站性能,这些方法都是不需要修改程序代码的.它们主要分为二个方面:1. 利用ASP.NET自身的扩展性进行优化.2. 优化IIS设置. 配置OutputCach ...
- Linux 安装tomcat,搭建web app运行环境
Tomcat 8 下载地址:https://tomcat.apache.org/download-80.cgi 解压tomcat:tar -xf apache-tomcat-8.5.31.tar.gz ...
- 根据 plist 还原 图片
1. python 环境自己配置(支持windows Mac ) 2. 把所有的 plist 和 大图片放到一个目录下 3.如果添加了 系统环境变量 就直接双击运行脚本,如果没有设置,把脚本拽到DO ...
- Hash破解神器:Hashcat的简单使用
Hash破解神器:Hashcat的简单使用 2014-06-10 21:02:42| 分类: 离线密码破解 | 标签:密码字典 rar密码破解 zip密码破解 密码破解 |举报|字号 订阅 ...
- php查询mysql返回大量数据结果集导致内存溢出的解决方法
web开发中如果遇到php查询mysql返回大量数据导致内存溢出.或者内存不够用的情况那就需要看下MySQL C API的关联,那么究竟是什么导致php查询mysql返回大量数据时内存不够用情况? 答 ...
- juey点击tr选中里面的radio
//点击一行选中银行卡 $("tr").bind("click",function(){ $("input:radio").attr(&qu ...
- 20行js代码制作网页刮刮乐
分享一段用canvas和JS制作刮刮乐的代码,JS部分去掉注释不到20行代码效果如下 盖伦.jpg 刮刮乐.gif HTML部分 <body>  &l ...
- 报错:/application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
启动zabbix_server时报错: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: li ...
- UUID工具类
在数据库中,一张数据表中的主键,通常会用自增的整型值或者UUID字符串来表示.其中,UUID可以产生全球唯一的标识符,从而确保主键的唯一. import java.util.UUID; /** * 工 ...
- 产生唯一的临时文件mkstemp()
INUX下建立临时的方法(函数)有很多, mktemp, tmpfile等等. 今天只推荐最安全最好用的一种: mkstemp. mkstemp (建立唯一临时文件)头文件: #include < ...