Poj 2010-Moo University - Financial Aid
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 9046 | Accepted: 2640 |
Description
Not wishing to admit dumber-than-average cows, the founders created an incredibly precise admission exam called the Cow Scholastic Aptitude Test (CSAT) that yields scores in the range 1..2,000,000,000.
Moo U is very expensive to attend; not all calves can afford it.In fact, most calves need some sort of financial aid (0 <= aid <=100,000). The government does not provide scholarships to calves,so all the money must come from the university's limited fund (whose total money is F, 0 <= F <= 2,000,000,000).
Worse still, Moo U only has classrooms for an odd number N (1 <= N <= 19,999) of the C (N <= C <= 100,000) calves who have applied.Bessie wants to admit exactly N calves in order to maximize educational opportunity. She still wants the median CSAT score of the admitted calves to be as high as possible.
Recall that the median of a set of integers whose size is odd is the middle value when they are sorted. For example, the median of the set {3, 8, 9, 7, 5} is 7, as there are exactly two values above 7 and exactly two values below it.
Given the score and required financial aid for each calf that applies, the total number of calves to accept, and the total amount of money Bessie has for financial aid, determine the maximum median score Bessie can obtain by carefully admitting an optimal set of calves.
Input
* Lines 2..C+1: Two space-separated integers per line. The first is the calf's CSAT score; the second integer is the required amount of financial aid the calf needs
Output
Sample Input
3 5 70 30 25 50 21 20 20 5 18 35 30
Sample Output
35
Hint
#include<iostream> #include<cstdio> #include<queue> using namespace std; const int N=1e5+1; typedef pair<int,int> P; P a[N]; int lower[N],upper[N]; int main() {int n,c,f;cin>>n>>c>>f;int half=n/2;for(int i=0;i<c;i++)cin>>a[i].first>>a[i].second;sort(a,a+c);{int total=0;priority_queue<int>q;for(int i=0;i<c;i++){lower[i]=q.size()==half?total:0x3f3f3f3f;q.push(a[i].second);total+=a[i].second;if(q.size()>half){total-=q.top();q.pop();}}}{int total=0;priority_queue<int>q;for(int i=c-1;i>=0;i--){upper[i]=q.size()==half?total:0x3f3f3f3f;q.push(a[i].second);total+=a[i].second;if(q.size()>half){total-=q.top();q.pop();}}}for(int i=c-1;i>=0;i--){if(a[i].second+upper[i]+lower[i]<=f){cout<<a[i].first<<endl;return 0;}}cout<<-1<<endl;return 0; }
转载于:https://www.cnblogs.com/widsom/p/6731033.html
Poj 2010-Moo University - Financial Aid相关推荐
- POJ 2010 Moo University - Financial Aid(堆维护滑窗kth,二分)
按照score排序,贪心,从左到右用堆维护并且记录前面的最小N/2个花费之和. 然后从右向左枚举中位数,维护N/2个数之和加上并判断是否满足条件.(stl的队列没有clear(),只能一个一个pop. ...
- POJ 2010 Moo University - Financial Aid【堆的应用】
题意: 给出 n 个人,知道了每个人的成绩,和每个人想要的奖学金,要求从这些学生中找出 m (奇数)个人满足选出的人的成绩的中位数最大,且这些人总的奖学金需求要 小于等于总的奖学金数. 分析: 可以 ...
- bzoj 3372: [Usaco2004 Feb]Moo University -- Financial Aid 财政补助(set+贪心)
3372: [Usaco2004 Feb]Moo University -- Financial Aid 财政补助 Time Limit: 10 Sec Memory Limit: 128 MB S ...
- POJ2010 Moo University - Financial Aid
题目链接:https://vjudge.net/problem/POJ-2010 题目大意: 有 \(C\) 头牛,每头牛有一个分数和需要资助的钱.现在要资助 \(N\) 头牛,总资助金额不能超过 \ ...
- POJ2010 Moo University - Financial Aid 优先队列
题目大意是有一批学生上大学,但是需要一些奖学金才上得起,学校给的奖学金aid有限,并且学校的教室只能让N个学生来上学,N为奇数,所以学校希望在在所有参加入学考试的C名学生中选取N个学生,为了提高教学质 ...
- POJ - 2008 Moo University - Team Tryouts
题目描述 给定dn组数据, 数据包括w, h, 给定a, b, c; 求一个子集, 子集里面所有的元素都满足A*(H-h) + B*(W-w) <= C w为子集里面最小的w , h表示子集里面 ...
- POJ 2231 Moo Volume(递推、前缀和)
题外话: POJ 2231 Moo Volume 题意: 解题过程: AC代码: 题外话: emm--第三套题好像综合了其他OJ的题目蛤,那么我就把题目分开了发了蛤蛤-- POJ 2231 Moo V ...
- poj 2010(优先队列)
题意: 奶牛大学:奶大招生,从C头奶牛中招收N头.它们分别得分score_i,需要资助学费aid_i.希望新生所需资助不超过F,同时得分中位数最高.求此中位数. 解题思路:这里要求最大中位数,中位数肯 ...
- 《挑战程序设计竞赛(第2版)》习题册攻略
本项目来源于GitHub 链接: 项目GitHub链接 1 前言 项目为<挑战程序设计竞赛(第2版)>习题册攻略,已完结.可配合书籍或笔记,系统学习算法. 题量:约200道,代码注释内含详 ...
最新文章
- mapreduce原理
- JAVA连接 mongodb(mac OSX)
- GRE tunnel源码分析之发送流程
- 慕课网 jupyter notebook魔法方法学习小记
- mmc_rescan_try_freq 简析
- ps基础学习:画笔工具实现花丛中蝴蝶效果
- Linux下php导出excel失败且浏览器报错500
- 美团O2O供应链系统架构设计解析
- c#中PROCESS的用法
- linux etc xdg,Xdg-menu (简体中文)
- VB SendMessage 函数
- SIGCOMM2022 Starvation in End-to-End Congestion Control
- python pdf open打开非常慢_openoffice打开大的word文档很慢而且兼容性极差
- WAP开发问答(1)简单的说WAP代表什么?
- 【原创】所谓“读心术”的伎俩
- 思科交换机使用TFTP工具备份配置和上传配置
- 怎么防抄板:从保护固件与安全认证开始
- 美团点评java开发面试问题
- php医疗管理系统(医院患者就诊档案管理系统)源码
- 一张图看懂阿里巴巴商业操作系统 1