UPCOJ 4201
来源:互联网 发布:淘宝店家一元拍 编辑:程序博客网 时间:2024/05/22 00:47
链接:
http://exam.upc.edu.cn/problem.php?id=4201
题目:
题目描述
Teacher’s Day is coming, a group of n students decided to buy gifts.
The store offered them M gifts. The price is different for different gifts, buying the j-th gift costs pj yuan.
In total, the boys’ shared budget is a yuan.Besides, each of them has his own personal money, the i-th student has bi personal yuan.The shared budget can be spent on any student, but each boy’s personal money can be spent on buying only his gift.
Each boy can rent at most one gift, one cannot give his gift to sombody else.What maximum number of students will able to buy gifts?What minimum sum of personal money will they have to spend in total to let as many students buy gifts as possible?
输入
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 1e5; 0 ≤ a ≤ 1e9). The second line contains the sequence of integers b1, b2, …, bn (1 ≤ bi ≤ 1e4), where bi is the amount of the i-th student’s personal money. The third line contains the sequence of integers p1, p2, …, pm (1 ≤ pj ≤ 1e9), where pj is the price for renting the j-th gift.
输出
Print two integers r and s, where r is the maximum number of students that can buy a gift and s is the minimum total personal money needed to buy r gifts. If the students cannot buy any gifts, then r = s = 0.
样例输入
2 2 10
5 5
7 6
样例输出
2 3
题意:
有n个人去商店,商店里有m个物品,有a元的班费,除此之外第i个人自己的钱包里还有
问你最多能买多少件物品,在保证购买物品最多的情况下,所有人最少可以花多少自己钱包里的钱。
思路:
对每个人拥有的钱和物品的价格排序一下,然后二分得到最多可以买到的物品数目k,然后将排序后的前k个物品的价格加和减去班费的钱,结果为负的话输出0就可以。
实现:
#include <iostream>#include <algorithm>#include <set>#include <string>#include <vector>#include <queue>#include <map>#include <stack>#include <list>#include <iomanip>#include <functional>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <cctype>//#define read read()#define edl putchar('\n')#define ll long long#define clr(a,b) memset(a,b,sizeof a)#define rep(i,m,n) for(ll i=m ; i<=n ; i++)#define fep(i,n) for(ll i=0 ; i<n ; i++)//inline ll read{ ll x=0;char c=getchar();while(c<'0' || c>'9')c=getchar();while(c>='0' && c<='9'){ x=x*10+c-'0';c=getchar(); }return x;}namespace FastIO { const ll SIZE = 1 << 16; char buf[SIZE], obuf[SIZE], str[60]; ll bi = SIZE, bn = SIZE, opt; ll read(char *s) { while (bn) { for (; bi < bn && buf[bi] <= ' '; bi++); if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } ll sn = 0; while (bn) { for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi]; if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } s[sn] = 0; return sn; } bool read(ll& x) { ll n = read(str), bf; if (!n) return 0; ll i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1; for (x = 0; i < n; i++) x = x * 10 + str[i] - '0'; if (bf < 0) x = -x; return 1; }};#define read(x) FastIO::read(x)using namespace std;const ll maxn = int(1e5)+7;ll n, m, a, p[maxn], cost[maxn];bool check(ll aim) { if(aim > m) return false; ll tmp = 0; for(ll i=0, j = n-aim ; i<aim ; i++, j++) { if(cost[i] > p[j]) tmp += cost[i] - p[j]; } return tmp <= a;}int main() {#ifndef ONLINE_JUDGE freopen("../1.in", "r", stdin);// printf("init! init! init!\n");#endif while(read(n)&&read(m)&&read(a)) { fep(i,n) read(p[i]); fep(i,m) read(cost[i]); sort(p,p+n); sort(cost,cost+m); ll l = 0, r = n, mid, ans = 0; while(l <= r) { mid = l+r>>1; if(check(mid)) { ans = mid; l = mid+1; } else r = mid-1; } printf("%lld ", ans); if(ans == 0) { puts("0"); continue; } ll result = 0; for(ll i=0 ; i<ans ; i++) { result += cost[i]; } printf("%lld\n",result - a); } return 0;}
- UPCOJ 4201
- UPCOJ 4333
- UPCOJ 4199
- UPCOJ 4198
- upcoj 2169 DP
- upcoj 2174 二维树状数组
- 线段树区间维护upcoj
- upcoj 2525 Twinkle Twinkle Little Star 题解
- upcoj 1975 棋盘覆盖二分匹配+2107单调队列+1109
- hdu 1542 upcoj 2540 矩形面积并 线段树
- [数位dp] upcoj 2223 A-Number and B-Number
- [思路题] upcoj 2219 A^X mod P
- [线段树+离线处理] upcoj 2224 Boring Counting
- 2013山东省赛D题 upcoj 2220: Rubik’s cube(爆搜)
- 【JZOJ 4201】【BZOJ 4177】Mike的农场
- 【经验交流】修复系统事件查看器启动不能时出现的4201错误
- 在ARM Linux上使用OpenGL(http://xianzilu.spaces.live.com/blog/cns!4201FDC93932DDAF!274.entry)
- 用于主题检测的临时日志(157cf0e4-6241-4201-95fb-159eac9e1c72 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
- HDU 2418 Another Easy Problem(模拟)
- jquery中$(":input")和$("input")有什么区别
- 爬虫学习笔记(三)——Re正则表达式
- HashMap的工作原理
- 机器学习与线性回归
- UPCOJ 4201
- TexturePacker免费申请注册码
- 二维关联数组转字符串
- HashMap相关问题
- 02-Nginx反向代理和负载均衡
- printf()格式化输出详解
- PAT甲级1002-写出这个数
- 递归显示文件夹下的所有目录(带绝对路径):并且解决中文乱码问题
- 使用BBR一键脚本为你的CentOS/Debian/Ubuntu系统加速