题意:
思路:
贪心 能不覆盖的就不盖
写得很乱 左闭右开的 temp
//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,l,temp,ans;
struct Node{int from,to;}node[10050];
priority_queue<Node>pq;
bool operator < (Node a,Node b){
return a.from>b.from;
}
int main(){
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++){
scanf("%d%d",&node[i].from,&node[i].to),node[i].to--;
pq.push(node[i]);
}
while(!pq.empty()){
Node t=pq.top();pq.pop();
if(temp<=t.from){
int rec=(t.to-t.from+1)/l;
ans+=rec;
temp=t.from+l*rec;
if(temp<=t.to)ans++,temp+=l;
}
else if(temp>t.to)
{
continue;
}
else{
int rec=(t.to-temp+1)/l;
ans+=rec;temp+=l*rec;
if(temp<=t.to)ans++,temp+=l;
}
}
printf("%d
",ans);
}