思路:堆贪心

提交:1次

题解:

先按时间\(sort\),然后如果能修就直接扔堆里,不能修取堆顶比一下时间长短,把时间短的扔进堆;

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#define ull unsigned long long
#define ll long long
#define R register int
using namespace std;
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
register char ch; while(isempty(ch=getchar()));
do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs; namespace Luitaryi {
const int N=150010;
struct node { ll w,t;
inline bool operator <(const node& that) const {return t<that.t;}
}a[N];
int n,cnt;
ll tot;
priority_queue<ll> q;
inline void main() {
n=g(); for(R i=1;i<=n;++i) a[i].w=g(),a[i].t=g();
sort(a+1,a+n+1);
for(R i=1;i<=n;++i) {
if(a[i].w+tot>a[i].t) {
if(a[i].w<q.top()) {
tot-=q.top(),q.pop();
tot+=a[i].w,q.push(a[i].w);
}
} else tot+=a[i].w,q.push(a[i].w),++cnt;
} printf("%d\n",cnt);
}
}
signed main() {
Luitaryi::main();
}

2019.07.22

最新文章

  1. 修改mysql默认字符编码出现的Job failed to start解决方法
  2. DataContract
  3. go框架
  4. HTML5_拖放
  5. hdoj 5391 Zball in Tina Town
  6. css的框架——base.css
  7. php中的双引号和单引号的区别?
  8. linux下可执行文件的库们
  9. Spring中的@conditional注解
  10. 通过user.MYD MySQL密码
  11. 通过WebChannel/WebSockets与QML中的HTML交互
  12. C#通过代码判断并注册程序集到GAC
  13. ActiveMQ安装配置及使用
  14. 题说proxy
  15. img2html实现将图片转换成网页
  16. 【Java入门提高篇】Day4 Java中的回调
  17. c读入实型
  18. mysql新手进阶02
  19. 【bzoj1649】Cow Roller Coaster
  20. 数据链路层负载均衡 Linux Virtual Server

热门文章

  1. 编写python高质量python代码的59个有效方法
  2. php文件操作类
  3. ORACLE的客户端、后台进程
  4. 模块 os 和 sys
  5. Maven配置、使用
  6. 13_日期时间、Math、枚举
  7. java中单双引号的区别
  8. win7+cuda+anaconda python+tensorflow-gpu+keras安装成功版本匹配汇总
  9. Angular 惰性路由
  10. 五、小程序wx:key中的关键字*this