Description

Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow i produces g_i gallons of milk (1 <= g_i <= 1000), but only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time starts at t=0, so at most x total cows can be milked prior to a deadline at time t=x. Please help Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally. 
 
 

Input

* Line 1: The value of N. 
* Lines 2..1+N: Line i+1 contains the integers g_i and d_i.

Output

* Line 1: The maximum number of gallons of milk Farmer John can obtain.

Sample Input

4
10 3
7 5
8 1
2 1
INPUT DETAILS: There are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on.

Sample Output

25
OUTPUT DETAILS: Farmer John milks cow 3 first, giving up on cow 4 since she cannot be milked by her deadline due to the conflict with cow 3. Farmer John then milks cows 1 and 2.
 
 
倒序加入堆里,每次取出个价值最大的
 #include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdlib>
using namespace std;
priority_queue<int> q;
int n,tm,num,ans;
struct dat{int c,w;}a[];
bool operator <(const dat &a,const dat &b){return a.c>b.c;}
int main()
{
q.empty();
scanf("%d",&n);
for (int i=;i<=n;i++)scanf("%d%d",&a[i].w,&a[i].c);
sort(a+,a+n+);
tm=a[].c;q.push(a[].w);num=;
a[n+].w=;a[n+].c=;
for (int i=;i<=n+;i++)
{
int go=min(tm-a[i].c,num);
while (go!=)ans+=q.top(),q.pop(),num--,go--;
q.push(a[i].w);num++;tm=a[i].c;
}
printf("%d\n",ans);
}

bzoj4096

bzoj4096 [Usaco2013 dec]Milk Scheduling的更多相关文章

  1. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: ...

  2. bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式

    后缀数组+二分答案+离散化.(上次写的时候看数据小没离散化然后一直WA...写了lsj师兄的写法. #include<cstdio> #include<cstring> #in ...

  3. [Usaco2006 Dec]Milk Patterns

    [Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天 产奶的质量,但连续的若干天的 ...

  4. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式( 二分答案 + 后缀数组 )

    二分答案m, 后缀数组求出height数组后分组来判断. ------------------------------------------------------------ #include&l ...

  5. BZOJ#1717:[Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+单调队列)

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的 ...

  6. BZOJ_1717_[Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组

    BZOJ_1717_[Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组 Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他 ...

  7. 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树

    [BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...

  8. 【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 后缀数组

    [BZOJ1717][Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量 ...

  9. bzoj 4094: [Usaco2013 Dec]Optimal Milking

    4094: [Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号为1 . ...

随机推荐

  1. 获取Android自己写好了的apk以及反编译

    今天,我们先说一下,获取Android自带的apk以及反编译它们来学习Android工程师是怎样写的,今天我们就以拿到Android自带的短信管理器的apk为例子 你可能有疑问,为什么要那么麻烦,从系 ...

  2. yii console.php 报错 Property "CConsoleApplication.theme" is not defined.

    默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...

  3. Ambari安装

    给hadoop用户sudo权限 hadoop ALL=(ALL) NOPASSWD:ALL 建立SSH互信,参考Hadoop HA的搭建中的互信建立 建立相应的下载脚本down.sh nohup wg ...

  4. MYSQL数据库命名与其设计规范

    你是否对获得MYSQL数据库命名与其设计规范 的实际操作感到十分头疼?如果是这样子的话,以下的文章将会给你相应的解决方案,以下的文章主要是介绍获得MYSQL数据库命名与其设计规范 的方案,以下就是相关 ...

  5. 运维监控利器smokeping 500报错处理

    检查apache日志发现有以下错误: No such file or directory: exec of '/usr/local/smokeping/htdocs/smokeping.cgi' fa ...

  6. C++ for 循环

    C++的另一种for循环写法,和C#的foreach语法很类似,不需要知道数组的类型: C++:for(auto& item:items) C#:foreach(var item in ite ...

  7. mysql window下tmpdir空间耗尽

    修改my.ini或my-default.ini文件[mysqld]下方配置 tmpdir = D:/tmp

  8. Win+PHP+IECapt完整实现网页批量截图并创建缩略图

    最近在开发一个本地互联网应用的项目,为了增加用户体验,需要在搜索结果左侧显示如图一所示的某个网站的缩略图效果,在网上不停地百度谷歌了一上午后,发现大多数实现少量截图还是可以的,如果大批量的截图总会在中 ...

  9. HTML5 Canvas 中的颜色、样式和阴影的属性和方法

    颜色.样式和阴影的属性与方法 fillStyle                设置或返回用于填充绘画的颜色.渐变或模式 strokeStyle         设置或返回用于笔触的颜色.渐变或模式 ...

  10. WDCP控制面板安装卸载

    安装 安装源码 WDCP提供两种安装模式,一种是源码安装,一种是RPM包安装,众所周知,源码安装虽然安装时要比RPM包安装繁琐,但是使用上要节省内存.所以我这里主要介绍源码安装. 首先是下载安装源代码 ...