Share Pastebin
Guest
Public paste!

khashi

By: a guest | Sep 9th, 2010 | Syntax: C++ | Size: 0.61 KB | Hits: 63 | Expires: Never
Copy text to clipboard
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int ans, n, l, tmp;
  7. pair<int, int>p[10000 + 10];
  8.  
  9. inline int saghf(int x, int y){
  10.         if(x % y == 0){
  11.                 return x / y;
  12.         }
  13.         return x / y + 1;
  14. }
  15.  
  16. int main(){
  17.         scanf("%d %d", &n, &l);
  18.         for(int i = 0; i < n; i++){
  19.                 scanf("%d %d", &p[i].first, &p[i].second);
  20.         }
  21.         sort(p, p + n);
  22.         tmp = -1;
  23.         for(int i = 0; i < n; i++){
  24.                 if(p[i].second > tmp + 1){
  25.                         p[i].first = max(tmp + 1, p[i].first);
  26.                         int x = saghf(p[i].second - p[i].first, l);
  27.                         ans += x;
  28.                         tmp = p[i].first + l * x - 1;
  29.                 }
  30.         }
  31.         printf("%d\n", ans);
  32.         return 0;
  33. }