fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. int32_t main()
  8. {
  9. int t;
  10. cin >> t;
  11.  
  12. while(t--)
  13. {
  14. int n;
  15. cin >> n;
  16.  
  17. map <int,vector <int> > m;
  18.  
  19. for(int i=0;i<n;i++)
  20. {
  21. int x,y;
  22. cin >> x >> y;
  23.  
  24. m[x].push_back(y);
  25. }
  26.  
  27. int ans = INT_MAX;
  28. multiset <int> s;
  29. auto end = --m.end();
  30. auto start = m.begin();
  31. bool flag = false;
  32.  
  33. while(start != end)
  34. {
  35. for(auto j:start->second)
  36. s.insert(j);
  37.  
  38. start++;
  39.  
  40. while(!s.empty() && *s.begin() < start->first)
  41. s.erase(s.begin()), flag = true;
  42.  
  43. if(flag)
  44. ans = min(ans,(int)s.size());
  45. }
  46.  
  47. if(ans == INT_MAX)
  48. cout << -1 << "\n";
  49. else
  50. cout << ans << "\n";
  51. }
  52. }
Time limit exceeded #stdin #stdout 5s 2100432KB
stdin
Standard input is empty
stdout
Standard output is empty