fork(1) download
  1. #include <bits/stdc++.h>
  2. typedef long long int ll;
  3. using namespace std;
  4.  
  5. int main() {
  6. ll test;
  7. cin>>test;
  8. for(ll t=1;t<=test;t++)
  9. {
  10. ll n, k;
  11. cin>>n>>k;
  12. vector< pair<ll,ll> > a;
  13. for(int i=0;i<n;i++)
  14. {
  15. ll start, end;
  16. cin>>start>>end;
  17. a.push_back(make_pair(start, end));
  18. }
  19. stable_sort(a.begin(), a.end());
  20.  
  21. cout<<"Case #"<<t<<": ";
  22. ll curr=0, count=0;
  23. for(int i=0;i<n;i++)
  24. {
  25. if(curr<a[i].second)
  26. {
  27. count++;
  28.  
  29. curr = max(curr, a[i].first) + k;
  30. }
  31. }
  32.  
  33. ll rem=a.back().second-curr;
  34. if(rem>0)
  35. {
  36. count+=rem/k;
  37. if(rem%k)
  38. count++;
  39. }
  40. cout<<count<<endl;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 4480KB
stdin
2
3 5
1 5
10 11
8 9
3 2
1 2
3 5
13 18
stdout
Case #1: 2
Case #2: 5