题目链接

给你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. SQL SERVER中变量的定义、赋值与使用

      本文面向对SQL SERVER中变量操作不熟悉的用户,希望能使他们在看完本文后能对变量操作有具体和全面的认识.   在学习SQL SERVER的过程中,很多时候需要对某些单独的值进行调试,这时就需 ...

  2. Linux PostgreSQL 基础配置指南

    1安装PostgreSQL:      yum install postgresql-server    2创建数据库          createdb mydb          如果出现以下错误 ...

  3. Windows 去掉启动时的放大镜

    控制面板-轻松访问中心-使计算机更易于显示不勾选 启用放大镜

  4. SQL Server中使用md5的方式

    在SQl2005下自带的函数hashbytes() ,此函数是微软在SQL SERVER 2005中提供的,可以用来计算一个字符串的 MD5 和 SHA1 值,使用方法如下: --获取123456的M ...

  5. Python进阶之decorator装饰器

    decorator装饰器 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB&quo ...

  6. seajs 学习笔记

    seajs的作者是玉伯,具体好处优点等详见官方网址 介绍 1 模块定义define define(function(require,exports,module){ //require 引入需要的模块 ...

  7. Flink资料(3)-- Flink一般架构和处理模型

    Flink一般架构和处理模型 本文翻译自General Architecture and Process Model ----------------------------------------- ...

  8. 点语法、property、self注意

    1.点语法(找出不合理的地方)#import <Foundation/Foundation.h>@interface Person : NSObject{    int _age;}- ( ...

  9. LINUX常用命令--重定向、管道篇(四)

    一.Linux重定向 重定向能够实现Linux命令的输入输出与文件之间重定向,以及实现将多个命令组合起来实现更加强大的命令.这部分涉及到的比较多的命令主要有: 涉及到的比较多的命令主要有: cat:连 ...

  10. Android使用VideoView播放网络视频

    Android支持播放网络上的视频.在播放网络上的视频时,牵涉到视频流的传输,往往有两种协议,一种是HTTP,一种是RTSP.这 两种协议最大的不同是,HTTP协议,不支持实时流媒体的播放,而RTSP ...