fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=3e4;
  5. const int MaxY=3e4;
  6. const int MaxP=1e5;
  7. int N,Y,A,B;
  8. int add[130002];
  9. int main() {
  10. while(cin>>N>>Y){
  11. for(int p=0;p<=MaxP+Y+1;p++)
  12. add[p]=0;
  13. for(int n=0;n<N;n++){
  14. cin>>A>>B;
  15. if(B-A>Y)
  16. continue;
  17. add[B]++;
  18. add[A+1+Y]--;
  19. //加夾子寬度
  20. }
  21. int now=0;
  22. for(int p=0;p<=Y;p++)
  23. now+=add[p];
  24. int ansC=0;
  25. int ansN=now;
  26. for(int p=Y+1;p<=MaxP+1+Y;p++){
  27. now+=add[p];
  28. if(now>ansN){
  29. ansN=now;
  30. ansC=1;
  31. }else if(now==ansN){
  32. ansC++;
  33. }
  34. }
  35. cout<<ansC<<" "<<ansN<<"\n";
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5300KB
stdin
5 4
1 3
2 5
3 6
2 6
5 7
5 4
1 3
2 5
3 6
2 5 
5 7
stdout
1 3
2 3