fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. #define int long long
  5.  
  6. int32_t main()
  7. {
  8. IOS;
  9. int t;
  10. cin >> t;
  11. int tc = 0;
  12. while(t--)
  13. {
  14. tc++;
  15. int n,k,i,x,y,limit=0;
  16. cin>>n>>k;
  17. vector<pair<int,int>>arr;
  18. for(i=0;i<n;i++){
  19. cin>>x>>y;
  20. arr.push_back({x,y});
  21. }
  22. sort(arr.begin(),arr.end());
  23. int ans=0;
  24. i=0;
  25. limit=arr[0].first;
  26. while(i<n){
  27. //cout<<limit<<endl;
  28. limit=limit + k;
  29. ans++;
  30. while(i<n && limit>=arr[i].second)
  31. i++;
  32. if(i<n && limit<arr[i].first){
  33. limit=arr[i].first;
  34. }
  35. }
  36. cout << "Case #" << tc << ": " << ans << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 4404KB
stdin
3
3 5
1 5
10 11
8 9
3 2
1 2
3 5
13 14
2 10
1 10
5 20
stdout
Case #1: 2
Case #2: 3
Case #3: 2