fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. int main()
  5. {
  6. using namespace std;
  7.  
  8. multimap<int, bool> ranges;
  9.  
  10. for (int start, end; cin >> start && cin >> end;)
  11. {
  12. ranges.emplace(start, true);
  13. ranges.emplace(end, false);
  14. }
  15.  
  16. int start, end, max = 0, current = 0;
  17. bool closing = false;
  18.  
  19. for (auto value : ranges)
  20. {
  21. current += value.second ? 1 : -1;
  22.  
  23. if (current > max)
  24. {
  25. start = value.first;
  26. max = current;
  27. closing = true;
  28. }
  29.  
  30. if (closing && !value.second)
  31. {
  32. closing = false;
  33. end = value.first;
  34. }
  35. }
  36.  
  37. cout << max << " (" << start << " -> " << end << ")\n";
  38. }
Success #stdin #stdout 0s 3432KB
stdin
60 95
15 40
55 62
92 100
17 30
2 20
stdout
3 (17 -> 20)