题目描述

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.

FJ有N(1 <= N <= 10,000)头牛要挤牛奶,每头牛需要花费1单位时间。

奶牛很厌烦等待,奶牛i在它的截止时间d_i (1 <= d_i <= 10,000)前挤g(1 <= g_i <= 1000)的奶,否则将不能挤奶。时间t开始时为0,即在时间t=x时,最多可以挤x头奶牛。

请计算FJ的最大挤奶量。

输入输出格式

输入格式:

  • Line 1: The value of N.

  • Lines 2..1+N: Line i+1 contains the integers g_i and d_i.

输出格式:

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

输入输出样例

输入样例#1:

4
10 3
7 5
8 1
2 1
输出样例#1:

25

说明

There are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on.

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.

倒序循环时间,把最后期限晚于当前时间的加入堆,贪心每次取一个最大值。

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
struct node{
int d,g;
}a[mxn];
int cmp(const node a,const node b){
return a.d>b.d;
}
priority_queue<int>tp;
int main(){
n=read();
int i,j;
for(i=;i<=n;i++){
a[i].g=read();
a[i].d=read();
}
sort(a+,a+n+,cmp);
int hd=;
int ans=;
for(i=a[].d;i;--i){
while(a[hd].d>=i){
tp.push(a[hd].g);
hd++;
}
if(tp.empty())continue;
ans+=tp.top();
tp.pop();
}
cout<<ans<<endl;
return ;
}

洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling的更多相关文章

  1. [USACO13DEC]牛奶调度Milk Scheduling

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4096 容易想到的一个测略就是,优先考虑结束时间小的牛.所以我们对所有牛按照结束时间排序.然 ...

  2. [洛谷P2852] [USACO06DEC]牛奶模式Milk Patterns

    洛谷题目链接:[USACO06DEC]牛奶模式Milk Patterns 题目描述 Farmer John has noticed that the quality of milk given by ...

  3. 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling 题解

    P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...

  4. 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling

    P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...

  5. P3074 [USACO13FEB]牛奶调度Milk Scheduling

    题目描述 Farmer John's N cows (1 <= N <= 10,000) are conveniently numbered 1..N. Each cow i takes ...

  6. 洛谷P3063 [USACO12DEC]牛奶的路由Milk Routing

    链接 其实在博客园里写题解都挺应付的都是在洛谷写了之后 挑一部分粘过来 在洛谷写的也都是废话,是为了凑篇幅 主要就是代码 大体思路就一提 这题贪心不行废话 跑m遍SPFA更新最小值 注意数组记得清空 ...

  7. 洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing

    P3063 [USACO12DEC]牛奶的路由Milk Routing 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 Farmer John's farm ...

  8. 洛谷 P1208混合牛奶【贪心】

    题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...

  9. 洛谷P3097 - [USACO13DEC]最优挤奶Optimal Milking

    Portal Description 给出一个\(n(n\leq4\times10^4)\)个数的数列\(\{a_n\}(a_i\geq1)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...

随机推荐

  1. 对js 面对对象编程的一些简单的理解

    由简单开始深入: 最简单的 直接对象开始 var desen = { age:24, name:'xyf', job:'fontEnd', getName:function(){ console.lo ...

  2. Lambda表达式。

    函数式编程思想: 面向对象思想:做一件事,先找能解决这件事的对象,然后调用该对象相应方法. 面向过程思想:只要能获取到结果,怎么做的不重要,重视结果,不重视过程. 冗余的代码: public stat ...

  3. 列表、margin和padding的探讨、标签的分类

    一.列表 列表分为无序列表.有序列表和自定义列表 1.无序列表   <ul></ul> 1).内部必须有子标签,<li></li> 2).ul天生自带内 ...

  4. C++模板类头文件和实现文件分离

    http://www.cnblogs.com/lvdongjie/p/4288373.html 如何实现C++模板类头文件和实现文件分离,这个问题和编译器有关. 引用<<C++primer ...

  5. 手把手教写devops全栈自动化工具(django2.1)

    简单介绍一下自己之前写的一个全栈项目,框架用的是django2.1版本 主要对paramiko模块,salstack的API二次开发. 核心组件包括:MQ,mysql,websocket,redis, ...

  6. SQLite_Home

    SQLite教程 SQLite是一个库,实现了一个独立的软件,serverless zero-configuration.事务SQL数据库引擎.SQLite是世界上最广泛的部署SQL数据库引擎.SQL ...

  7. Java异常归纳

      1.使用Tomcat运行“播报哥架构”出现的两大异常 1.1 监听器异常 详细情况:部署好Maven项目,启动TOMCAT提示如下错误 java.lang.ClassNotFoundExcepti ...

  8. nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token

    nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token 注意: proxy_pass http://192.168.40.54:22 ...

  9. 输入防抖 vue # 输入搜索的时候 及时搜索的快速访问接口的 解决方案 vue 中使用防抖和节流

    输入防抖 watch: { value (newVal, oldVal) { if (this.timer) { clearTimeout(this.timer) } this.timer = set ...

  10. css--字体和文本样式

    文字样式属性 字体:font-family 文字大小:font-size 文字颜色:font-color 文字粗细:font-weight 文字样式:font-style font-family字体属 ...