codeforces 377B Preparing for the Contest 二分+优先队列
给你m个bug, 每个bug都有一个复杂度。n个人, 每个人有两个值, 一个是能力值, 当能力值>=bug的复杂度时才可以修复这个bug, 另一个是雇佣他需要的钱,掏一次钱就可以永久雇佣。 然后给你一个金钱总额, 让你在最短的时间的修复这些bugs, 并且给出每个bug是由谁修复的, 一个人一天只能修复一个bug。
首先, 对bug的复杂度由高到低排序, 对人的能力值由高到低排序。 这时候需要二分修复的时间, 假设需要的时间是t, 那么显然, 一个人一共可以修复t个bug, 因为有t天。
在开始之前, 先把能力值大于第一个bug的复杂度的人全都加入一个优先队列中, 队列按价钱由小到大排序。 然后前t个bugs都由队列首的这个人修复, 之后将这个人pop。到第1+t个bug的时候, 把能力值大于第二个复杂度的人全都入队列, 因为人是按能力值大小排序的, 所以之前在队列中的人同样可以修复第二个bug,然后不断这样循环就可以。
如果在过程中队列空了或者是价钱大于了给定的总额, 就直接返回false。
在二分之前先测试一下时间为m的时候是否可行, 如果不可行就直接输出no, 因为这是最长的时间。
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
struct node
{
int sk, pr, id;
bool operator <(node a) const
{
return pr>a.pr;
}
};
bool cmp(node a, node b) {
return a.sk > b.sk;
}
const int maxn = 1e5+;
int n, m, cost, ans[maxn];
node st[maxn], pro[maxn];
int check(int t) {
int tmpcost = cost;
priority_queue <node> q;
for(int i = , j = ; j<=m; j+=t) {
while(i<=n&&st[i].sk>=pro[j].sk) {
q.push(st[i]);
i++;
}
if(q.empty()) {
return ;
}
tmpcost -= q.top().pr;
for(int tmp = j; tmp<min(j+t, m+); tmp++) {
ans[pro[tmp].id] = q.top().id;
}
if(tmpcost<)
return ;
q.pop();
}
return ;
}
int main()
{
cin>>n>>m>>cost;
for(int i = ; i<=m; i++) {
scanf("%d", &pro[i].sk);
pro[i].id = i;
}
for(int i = ; i<=n; i++) {
scanf("%d", &st[i].sk);
}
for(int i = ; i<=n; i++) {
scanf("%d", &st[i].pr);
st[i].id = i;
}
sort(pro+, pro++m, cmp);
sort(st+, st++n, cmp);
int flag = ;
for(int i = ; i<=n; i++) {
if(st[i].sk>=pro[].sk&&st[i].pr<=cost)
flag = ;
}
if(!flag) {
cout<<"NO"<<endl;
return ;
}
int l = , r = m, ret;
while(l<=r) {
int mid = l+r>>;
if(check(mid)) {
r = mid-;
ret = mid;
}
else
l = mid+;
}
check(r+);
cout<<"YES"<<endl;
for(int i = ; i<=m; i++) {
cout<<ans[i]<<" ";
}
}
codeforces 377B Preparing for the Contest 二分+优先队列的更多相关文章
- Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树
B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...
- CodeForces - 847B Preparing for Merge Sort 二分
http://codeforces.com/problemset/problem/847/B 题意:给你n个数(n<2e5)把它们分成若干组升序的子序列,一行输出一组.分的方法相当于不断找最长递 ...
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Preparing for the Contest
Codeforces Round #222 (Div. 1)B:http://codeforces.com/contest/377/problem/B 题意:m个任务,每个任务会有一个复杂度,然后给 ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces 689C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
随机推荐
- javascript高级知识分析——作为对象的函数
代码信息来自于http://ejohn.org/apps/learn/. 函数和对象是不是非常相似? var obj = {}; var fn = function(){}; console.log( ...
- Spring IOC的描述和Spring的注解(转)
Spring常用的注解 本文系转载:转载网址: http://www.cnblogs.com/xdp-gacl/p/3495887.html http://ljhzzyx.blog.163.com/b ...
- spring学习参考资料
http://www.cnblogs.com/ooooevan/p/5795456.html http://blog.csdn.net/hongjun1847/article/details/2053 ...
- EassyMock实践 自定义参数匹配器
虽然easymock中提供了大量的方法来进行参数匹配,但是对于一些特殊场合比如参数是复杂对象而又不能简单的通过equals()方法来比较,这些现有的参数匹配器就无能为力了.easymock为此提供了I ...
- leetcode Remove Duplicates from Sorted Array python
class Solution(object): def removeDuplicates(self,nums): if len(nums) <= 0: return 0 j=0 for i in ...
- ExtJS4.x Grid 单元格鼠标悬停提示
//每一个列都会出现鼠标悬浮上去显示内容 /** * //适用于Extjs4.x * @class Ext.grid.GridView * @override Ext.grid.GridView * ...
- node anyproxy ssi简易支持
在项目中,ssi include是一个比较常用的功能,这样我们就可以通过web服务器的支持,将公用的html提取出来,改一个文件就会修改全部内容 但是这也带来了问题,在开发的时候没办法的刷新查看,需要 ...
- Flink资料(8) -- Flink代码贡献的指导及准则
本文翻译自Contributing Code ----------------------------------------- Apache Flink是由自愿的代码贡献者维护.优化及扩展的.Apa ...
- getchar()与EOF
大师级经典的著作,要字斟句酌的去读,去理解.以前在看K&R的The C Programming Language(Second Edition)中第1.5节的字符输入/输出,很迷惑getcha ...
- android一分钟学会可视化操作数据库(无需ROOT)
我刚开始弄android数据库的时候,想查询一些数据,以验证程序逻辑,发现很多方案都需要ROOT. 即便有不需要ROOT的方案,命令行交互也比较麻烦. 今天跟大家分享一下这个点点鼠标就能实现的功能. ...