题目描述:

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.

Examples

Input

2 2 10
5 5
7 6

Output

2 3

Input

4 5 2
8 1 1 2
6 3 7 5 2

Output

3 8

Note

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.

题目大意:

在第一行输入三个值,第一个是人的数量,第二个是可以租的车的数量,以及公款。

然后输入的这n个人的私款,以及租每辆车的价格钱数

需要你做的是能租最多的车,以及花费自己的私款最少,并且每个人的私款只能用来自己租自行车

思路(贪心+二分)

既然想要花费自己的私款最少,就让有钱的人去租便宜的自行车,这样下来肯定花费私款(自己的钱)才相对较少,并且租的自行车还相对多,故利用二分把可以租的车的范围确定下来

具体思路的实现见代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
int a[100005],b[100005]; //用来存储人的私款和租车价格
long long int judge(int x)//这个是在模拟比较私款数和租车价钱
{
long long int sum=0;
for(int t=0;t<x;t++)
{
if(a[n-x+t]<b[t])
{
sum+=(b[t]-a[n-x+t]);//这是相当于钱不够,需要公款支援
}
}
return sum;//这是需要公款支援的总数
}
int main()
{ cin>>n>>m>>k;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
for(int t=0;t<m;t++)
{
scanf("%d",&b[t]);
}
sort(a,a+n);
sort(b,b+m);
//用二分来确定可以租的车数
int left=0;
int right=min(n,m);//二分是由小的一部分决定的,比如人数少,提供的车多,一旦二分很有可能这一部分这一部分没有相对应的另一部分
//以上说法如果不太明白可以去假设几个去试试应该就理解了
int s=0;//用来表示买的车数
while(left<=right)
{ int mid=(left+right)>>1;
//判断需要的公款和提供的公款进行比较
//如果小于则说明买完mid辆车还可以买,所以往后继续找可以买的车,否则往前找
if(judge(mid)<=k)
{
left=mid+1;
s=mid;
}
else
{
right=mid-1;
}
}
//找完买了多少辆车后可以把租这些车的价钱求和
long long int sum=0;
for(int t=0;t<s;t++)
{
sum+=b[t];
}
//这时候的sum就是需要的私款数
if(sum>k)
{
sum=sum-k;
}
//公款够,不需要私款,就不能减,不然出负数,显然不对
else
{
sum=0;
}
printf("%d %lld\n",s,sum);
return 0;
}

rent bike问题(二分+贪心)的更多相关文章

  1. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  2. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

  3. 【bzoj2097】[Usaco2010 Dec]Exercise 奶牛健美操 二分+贪心

    题目描述 Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点之间恰好有一条简单路径. ...

  4. Codeforces_732D_(二分贪心)

    D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  5. CF732D Exams 二分 贪心

    思路:二分+贪心 提交次数:10次以上 错因:刚开始以为二分(边界,$+1or-1$)写错了,调了半天,后来才发现是$ck()$写错了.开始只判了最后是否小于零,而应该中间一旦小于零就$return\ ...

  6. $CF949D\ Curfew$ 二分/贪心

    正解:二分/贪心 解题报告: 传送门$QwQ$ 首先这里是二分还是蛮显然的?考虑二分那个最大值,然后先保证一个老师是合法的再看另一个老师那里是否合法就成$QwQ$. 发现不太会搞这个合不合法的所以咕了 ...

  7. $bzoj2067\ szn$ 二分+贪心

    正解:二分+贪心 解题报告: 传送门$QwQ$ 题目大意就说有一棵树,然后要用若干条线覆盖所有边且不能重叠.问最少要用几条线,在用线最少的前提下最长的线最短是多长. 昂首先最少用多少条线这个还是蛮$e ...

  8. leetcode1552题解【二分+贪心】

    leetcode1552.两球之间的磁力 题目链接 算法 二分+贪心 时间复杂度O(nlogn + nlogm) 1.根据题意描述,我们需要将m个球放入到n个篮子中,根据题目中数据范围描述发现m &l ...

  9. CF2.C(二分贪心)

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. 探究QA职能

    测试人员一般是被外界普遍认为是QC,即对产品的质量进行检测,找出质量问题并配合相关人员解决问题,从而管控产品质量,说通俗点就是帮开发找漏洞,给开发擦屁股:如果线上出现bug,就是你没有测试完整,最累的 ...

  2. java多线程编程——同步器Exchanger

    类java.util.concurrent.Exchanger提供了一个同步点,在这个同步点,一对线程可以交换数据.每个线程通过exchange()方法的入口提供数据给他的伙伴线程,并接收他的伙伴线程 ...

  3. 探索Web Office Apps服务

    老样子,先放几个官链: WOA部署规划:http://technet.microsoft.com/zh-cn/library/jj219435(v=office.15).aspx 拓扑规划:http: ...

  4. Codeforces 58E Expression (搜索)

    题意:给你一个可能不正确的算式a + b = c, 你可以在a,b,c中随意添加数字.输出一个添加数字最少的新等式x + y  = z; 题目链接 思路:来源于这片博客:https://www.cnb ...

  5. linux鸟哥的私房菜

    这书还是感觉非常棒,真的是授之以渔而不是授之以鱼.我觉得只需要掌握一个命令就可以了man -k KEYWORD 比如我想查找和防火墙相关的命令,那么 man -k firewall 结果是ufw 然后 ...

  6. Conda / Miniconda——软件包管理系统使用

    conda是一个非常好的python包管理软件,但是它的Minicoda是一个非常好的生信软件包管理软件,更多conda介绍多google. Miniconda简直就是生信人的福音,尤其是像我这种传统 ...

  7. Luogu 2737 [USACO4.1]麦香牛块Beef McNuggets

    NOIP2017 D1T1 的结论,两个数$a, b$所不能表示出的最大的数为$a * b - a - b$. 听了好几遍证明我还是不会 注意到本题中给出的数都非常小,所以最大不能表示出的数$\leq ...

  8. JButton ButtonClickTest

    package com.example.test; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing. ...

  9. WinForm(C#)相关知识和经验的碎片化记录

    1.引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常 出现"System.Windows.Forms.Ax ...

  10. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...