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都表示服务器成功处理了请求的状态代码,说 ...
随机推荐
- LightOJ1214 Large Division 基础数论+同余定理
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- Do the Untwist(模拟)
ZOJ Problem Set - 1006 Do the Untwist Time Limit: 2 Seconds Memory Limit: 65536 KB Cryptography ...
- Vue 子路由 与 单页面多路由 的区别
本文地址:http://www.cnblogs.com/veinyin/p/7911292.html 最近学完了基础课程,打算整理一波笔记,对基本概念梳理一遍,惊觉对子路由和单页面多路由混淆的一塌糊涂 ...
- 用java代码在创建hbase表时指定region的范围
package com.liveyc.common.utils; import java.util.List; import org.apache.hadoop.hbase.util.Bytes; i ...
- perl6 Socket
Perl6 中的SOCKET就是相当于Perl5 的 IO::Socket::INET. 官方介绍如下: #下面是客户端multi method new( :$host, :$port, :, :$e ...
- php webshell常见函数
0x1 直接在字符串变量后面加括号, 会调用这个函数: <?php $s = 'system'; $e = 'assert'; $s('whoami'); $e('phpinfo();'); 0 ...
- webgote的例子(5)Sql注入(Blog)
SQL Injection - Stored (Blog) (本章内容):留言板的注入 看到这个页面先看以下这个页面是做什么的.进行正常的写入发现我每写一句话,其内容都会写到下面的entry里面 在尝 ...
- 自动化测试===adb 解锁手机的思路
在adb里有模拟按键/输入的命令 比如使用 adb shell input keyevent <keycode> 命令,不同的 keycode 能实现不同的功能,完整的 keycode 列 ...
- git-定制属于你的log格式
软件版本: 操作系统:ubuntu10.04 内核版本:Linux version 2.6.32-36-generic git 版本:git version 1.7.0.4 1. ...
- jmeter主要组件
1.测试计划(Test plan) 2.线程组(Thread Group) 3.配置原件(Configuration) 4.逻辑控制器(Login Controller) 5.取样器(Sampler) ...