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. 多表关联查询(ORACLE版)

    前言:这几天学习oracle,把自己对于关联查询的理解,记录下.如有错误请指正! 交叉连接: 交欢连接又称为“笛卡儿积连接”,是两个或多个表之间的无条件连接.一个表中所有的记录与其它表的所有的记录进行 ...

  2. [转] 强大的python字符串解析

    1.python字符串通常有单引号('...').双引号("...").三引号("""...""")或('''...'' ...

  3. [转] 浅谈 C++ 中的 new/delete 和 new[]/delete[]

    转:http://www.cnblogs.com/hazir/p/new_and_delete.html 在 C++ 中,你也许经常使用 new 和 delete 来动态申请和释放内存,但你可曾想过以 ...

  4. ifconfig命令详解

    linux下网上命名规律:eth0,eth1.第一块以太网卡,第二块.lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身. 1.ifconfig是查看网卡的信息 eth ...

  5. python基础-软件目录开发规范

    为什么要设计好目录结构? "设计项目目录结构",就和"代码编码风格"一样,属于个人风格问题.对于这种风格上的规范,一直都存在两种态度: 一类同学认为,这种个人风 ...

  6. await, anync

    public Form1() { InitializeComponent(); } // The following method runs asynchronously. The UI thread ...

  7. sql数据库之间数据的转录

    private void Form1_Load(object sender, EventArgs e) { BindDataBase(combDataBaseNew, , ""); ...

  8. Android Studio 实用快捷键

    ctrl + alt + 方向键   跳转到上次或下次编辑位置 ctrl + alt +n   查找文件 shift + f6       重构之重命名 ctrl + f12       导航到类方法 ...

  9. Android学习手记(1) Activity跳转

    新建Project,并将主页命名为MainActivity. 创建一个Activity 在App上“右键->New->Activity->Empty Activity”, 将新建的A ...

  10. c-100米球反弹

    #include <iostream> #define TIMES 10 int main(void) { ; ; //第一次反弹的高度. ; i <= TIMES; i++) { ...