博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D. Renting Bikes 二分
阅读量:4986 次
发布时间:2019-06-12

本文共 3379 字,大约阅读时间需要 11 分钟。

D. Renting Bikes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
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.

二分找最大的车数。。。。。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//ios_base::sync_with_stdio(false);//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define sz(v) ((int)(v).size())#define rep(i, a, b) for (int i = (a); i < (b); ++i)#define repf(i, a, b) for (int i = (a); i <= (b); ++i)#define repd(i, a, b) for (int i = (a); i >= (b); --i)#define clr(x) memset(x,0,sizeof(x))#define clrs( x , y ) memset(x,y,sizeof(x))#define out(x) printf(#x" %d\n", x)#define sqr(x) ((x) * (x))typedef long long LL;const int INF = 1000000000;const double eps = 1e-8;const int maxn = 300000;int b[maxn];int p[maxn];int main() { //freopen("in.txt","r",stdin); int n,m,a; while(cin>>n>>m>>a) { repf(i,1,n) scanf("%d",&b[i]); repf(i,1,m) scanf("%d",&p[i]); int ans = 0; sort(b+1,b+1+n); sort(p+1,p+1+m); int Min = min(n,m); int L = 0; int R = Min; int mid; while(L <= R) { int temp = a; mid = (L+R)/2; int i; for(i = n-mid +1;i<=n;++i) { int gap = p[i - (n-mid+1)+1] - b[i]; if(gap > 0) { if(temp>=gap) { temp-=gap; }else { break; } } } if(i == n+1) { L = mid + 1; }else R = mid - 1; } repf(i,1,R) ans+=p[i]; cout<
<<" "<

 

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3418522.html

你可能感兴趣的文章
如何通过命令行使用Wisdom RESTClient?
查看>>
class样式实现个人签名,一定字数后省略号取代后面内容
查看>>
设计模式之组合模式
查看>>
hdu_1690 (第一次做最短路)
查看>>
POJ 1321-棋盘问题
查看>>
漫谈测试人员和开发人员关系
查看>>
IOC
查看>>
Leetcode 374. Guess Number Higher or Lower
查看>>
统计学习方法一:基础
查看>>
2018-2019-1 20165236 《信息安全系统设计基础》第一周学习总结
查看>>
Jmeter-添加自定义函数
查看>>
每个Java程序员需要了解的8个Java开发工具
查看>>
【转】【Android】事件输入系统-代码层次解读
查看>>
WebMisSharp的协同开发
查看>>
ios 集成react native
查看>>
【Alpha】Scrum Meeting 6
查看>>
localhost、127.0.0.1、192.168.xx.xx 的区别
查看>>
实现画茶壶,圆环,盒子,球体
查看>>
HTML特殊转义字符对照表
查看>>
http协议和web本质
查看>>