khashi
By: a guest | Sep 9th, 2010 | Syntax:
C++ | Size: 0.61 KB | Hits: 63 | Expires: Never
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int ans, n, l, tmp;
pair<int, int>p[10000 + 10];
inline int saghf(int x, int y){
if(x % y == 0){
return x / y;
}
return x / y + 1;
}
int main(){
scanf("%d %d", &n, &l);
for(int i = 0; i < n; i++){
scanf("%d %d", &p[i].first, &p[i].second);
}
sort(p, p + n);
tmp = -1;
for(int i = 0; i < n; i++){
if(p[i].second > tmp + 1){
p[i].first = max(tmp + 1, p[i].first);
int x = saghf(p[i].second - p[i].first, l);
ans += x;
tmp = p[i].first + l * x - 1;
}
}
printf("%d\n", ans);
return 0;
}