题目链接

给你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 二分+优先队列的更多相关文章

  1. 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 ...

  2. CodeForces - 847B Preparing for Merge Sort 二分

    http://codeforces.com/problemset/problem/847/B 题意:给你n个数(n<2e5)把它们分成若干组升序的子序列,一行输出一组.分的方法相当于不断找最长递 ...

  3. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  4. Preparing for the Contest

     Codeforces Round #222 (Div. 1)B:http://codeforces.com/contest/377/problem/B 题意:m个任务,每个任务会有一个复杂度,然后给 ...

  5. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  6. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  7. 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 ...

  8. Codeforces 689C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...

  9. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

随机推荐

  1. Nicholas C. Zakas如何面试前端工程师

    转载自:http://www.cnblogs.com/yizuierguo/archive/2010/02/04/1663767.html Original Post:Interviewing the ...

  2. some knowledge t

    NSNumber static 看下面例子  gCount可以在Person 文件中使用  在main 中不行 @property()括号中可以填的属性 国际化 OC中的快捷键操作 operation ...

  3. ES6笔记② 箭头函数

    特性介绍 箭头函数是ES6新增的特性之一,它为JS这门语言提供了一种全新的书写函数的语法. //ES5 function fun(x,y){ return x+y; } console.log(fun ...

  4. 控制台下的计算器——C++实现

    最近这段时间看操作系统的东西看的头晕脑胀的,所以先停个一晚上,写个控制台下的计算器,来练练栈的使用. 首先,分析一下要完成的东西.输入肯定使用string类来输入的,然后第一步,就是把string的字 ...

  5. beego任务定时执行,延迟执行

    import ( "github.com/astaxie/beego" "github.com/astaxie/beego/toolbox") cronExpr ...

  6. Eclipse --Type /com.xx.app/gen already exists but is not a source folde解决方案

    两种解决方案: Two actions, first: 1.Right click on the project and go to "Properties" 2.Select & ...

  7. Unhandled Exxception “Unhandled exception type IOException”?

    Unhandled Exxception  “Unhandled exception type IOException”? 在Android studio中,自动遇见这个异常报错,如果eclipse会 ...

  8. CakePHP 2.x 升级3.0

    CakePHP 2.x => 3.x 升级手顺 一.Controller层 1.find('list') 原2.x中该方法通过指定option中的'fields'来实现key=>value ...

  9. python3--(变量)

    变量: Python 是动态类型语言, 也就是说不需要预先声明变量的类型.变量是对象的引用,变量只是将指针指向了对象所在的内存地址.变量的类型和值在赋值那一刻被初始化. 变量起名: 1.显式--> ...

  10. 简单的实现树莓派的WEB控制

    最终效果如图: 用到的知识:Python Bottle HTML Javascript JQuery Bootstrap AJAX 当然还有 linux 我去,这么多--我还是一点一点说起吧-- 先贴 ...