题目描述:

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. DAY18-Django之form表单

    构建一个表单 假设你想在你的网站上创建一个简单的表单,以获得用户的名字.你需要类似这样的模板: <form action="/your-name/" method=" ...

  2. struct-config.xml配置文件的解析

    //定义了xml文件的版本和编码<?xml version="1.0" encoding="UTF-8"?>//配置文件中的元素必须按照下述doc指 ...

  3. C++中cin.get(),cin.getline(),cin>>,gets(),cin.clear()使用总结

    1.cin.get()  实质:类istream所定义对象cin的重载成员函数 用于读取单字符  istream& get(char&)    int get(void) 用于读取字符 ...

  4. linux磁盘分区fdisk分区和parted分区

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 磁盘分区 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  5. 最短路dijkstra堆优化

    demo: #include<bits/stdc++.h> #define max_v 102000 #define inf 0x3f3f3f3f using namespace std; ...

  6. apaache php 日记设计

    有个客户服务器是用apache搭建的,最近总是感觉站很慢,服务器很慢很卡,有时候甚至网 站都打不开,后来经过排查分析原来是里面的access.log和error.log这两个文件要经常上去看,和清理, ...

  7. Luogu 3626 [APIO2009]会议中心

    很优美的解法. 推荐大佬博客 如果没有保证字典序最小这一个要求,这题就是一个水题了,但是要保证字典序最小,然后我就不会了…… 如果一条线段能放入一个区间$[l', r']$并且不影响最优答案,那么对于 ...

  8. 第四章输入/输出(I/O)4.2PCL中I/O模块及类介绍

    PCL中I/O库提供了点云文件输入输出相关的操作类,并封装了OpenNI兼容的设备源数据获取接口,可直接从众多感知设备获取点云图像等数据.I/O模块利用21个类和28个函数实现了对点云的获取.读入.存 ...

  9. win10开机时不显示锁屏壁纸

    win10开机壁纸存放在此目录下: C:\Users\%username%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManage ...

  10. HttpGet和HttpPost处理重定向的区别

    get方法默认会处理302的重定向,response获取到的页面其实是重定向以后的页面,通过response.getStatusLine(),取到的值是200. 通过设置可以用post方法去请求或者把 ...