Renting Bikes

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 nm and a (1 ≤ n, m ≤ 1050 ≤ 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

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

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.


一堆人租自行车,有共有的资金和私人资金。私人资金只能给自己用,共有资金可以通用。列出n个人的钱,然后列出m辆车的租费,求最大租车数以及个人最少花的钱 。


一开始想法是先让钱少的人选,不够就拿公用资金,然后发现不行,因为有可能花了所有钱给他买一辆车,还不如给那些钱多但是差价少的人;于是改为从大到小再选一次,但是对称的问题是,钱多的也有可能出现上述问题。所以我就想大小各搜一遍,然后比较,事实证明,还是不行,因为还有可能是中间的取最大值,什么乱七八糟的想法。


贪心做得太多了,成傻子了,老是把问题简单化,毕竟是个div.2的d题。首先选车这个问题就想错了。如果能选k辆车,那么正确的姿势应该是选k个钱多的人,和k个租费少的车,然后一一对应,并用上共同资金。现在就有一个问题,确定k的值。


遍历一遍?呵呵……超时了。然后这个时候就会发现,如果你k辆车都租不到,还谈k+1个球啊,就是说,如果k不行,那么k之后的都不可以,是不是想到了什么?对,二分法。取中点,判断中点是否满足,如果满足,就选(k+1,r)区间再找,如果不满足,就是(l,k-1)再找,这样就可以降低复杂度了。虽然写的很蛋疼,但是做难题是有提升的,尤其是这种差一点就可以的题目。另外,是找到了买车的方法才找到的二分法,并不是刻意的套思想,也不是平白无故出来的想法。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
 int b[100005], p[100005];
int  max( int a,  int b)
{
	return a > b ? a : b;
}
 int min( int a,  int b)
{
	return a < b ? a : b;
}
int main()
{
	 int i, j, m, n, ans, a, sum, pre, num, leap;
	cin >> n >> m >> a;
	for (i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (i = 1; i <= m; i++)
		scanf("%d", &p[i]);
	sort(b + 1, b + 1 + n);
	sort(p + 1, p + 1 + m);
	int l, r, mid;
	l = 0; r = min(n, m); mid = (l + r) / 2; sum = 0;
	while (l<=r)
	{
		leap = 0;
		pre = a;
		for (i = 1; i <= mid; i++)
		{
			if (b[n - mid + i] >= p[i])continue;
			else if (b[n - mid + i] + pre >= p[i])
			{
				pre = pre - (p[i] - b[n - mid + i]);
			}
			else if (b[n - mid + i] + pre < p[i])
			{
				leap = 1; break;
			}
		}
		if (leap)
		{
			r = mid - 1;
			mid = (l + r) / 2;
		}
		else
		{
			sum = max(sum, mid);
			l = mid + 1;
			mid = (l + r) / 2;
		}
	}
	num = -a;
	for (i = 1; i <= sum; i++)
		num = num + p[i];
	cout << sum << " " << max(0, num) << endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值