难度在于读题

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> > q;
struct node{
int l,r;
}e[1000005];
bool cmp(node a,node b){
return a.l<b.l;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for (int i=1; i<=n; i++){
int x,y;
scanf("%d%d",&x,&y);
e[i]=(node){x,x+y};
}
sort(e+1,e+n+1,cmp);
q.push(e[1].r+m);
int ans=0;
for (int i=2; i<=n; i++){
while (!q.empty() && q.top()<e[i].l) q.pop();
if (!q.empty()){
int now=q.top();
if (e[i].l>=now-m){
ans++;
q.pop();
}
}
q.push(e[i].r+m);
}
printf("%d\n",ans);
return 0;
}

  

最新文章

  1. CJCMS系列---说说项目中的缓存实现(1)
  2. css 权重
  3. asp.net gridview动态添加列,并获取其数据;
  4. linux备忘
  5. SQL Server常用命令
  6. Google 面试题和详解
  7. ubuntu下简单的驱动编译
  8. HoloLens开发手记 - 开始使用Vuforia Getting started with Vuforia
  9. 机器学习 —— 类不平衡问题与SMOTE过采样算法
  10. ”dpkg: 处理归档 /var/cache/apt/archives/XXXXXX(--unpack)时出错“的解决方法
  11. Python中不尽如人意的断言Assertion
  12. HTTP与HTTPS有哪些区别?
  13. HanLP中人名识别分析
  14. [CocoaPods]入门
  15. nodejs中引用其他js文件中的函数
  16. python中的%s%是什么意思
  17. Andorid开发(二十二)——获取上下文getApplicationContext()、Activity.this、 getBaseContext
  18. python 开发学习
  19. OpenGL教程(25) skybox
  20. Thread 1 cannot allocate new log的问题分析 (转载)

热门文章

  1. 如何更改Android的默认虚拟机地址(Android virtual driver路径设置)
  2. 在MasterPage中检验session是否存在~
  3. 洛谷P1965 转圈游戏
  4. c#基础-构造函数 this new
  5. AJPFX辨析Java中堆内存和栈内存的区别
  6. IO(File、递归)
  7. 织梦修改文档HTML默认保存路径
  8. 1.2 the structure of a compiler
  9. 【Python图像特征的音乐序列生成】关于音乐生成的思路转变
  10. Netweaver和CloudFoundry是如何运行Web应用的?