Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define fr first
  6. #define sc second
  7. #define in insert
  8.  
  9. using namespace std;
  10.  
  11. vector <pair<int, int> > a;
  12. int n, ans, k, t;
  13.  
  14. int main()
  15. {
  16. cin >> n >> t;
  17. for (int i = 0; i < n; i++)
  18. {
  19. int x, y;
  20. cin >> x >> y;
  21. a.pb(mp(x, y));
  22. }
  23. sort(a.begin(), a.end());
  24. int tt = 0, tans = 0, k = 0;
  25. for (int i = 0; i < n; i++)
  26. {
  27. tt = a[i].fr;
  28. tans = 1;
  29. for (int j = k; j < i; j++)
  30. if (a[i].fr > a[j].sc)
  31. continue;
  32. else
  33. {
  34. k = j;
  35. break;
  36. }
  37. tans -= i - k;
  38. for (int j = i + 1; j < n; j++)
  39. {
  40. if (a[j].fr > tt + t)
  41. break;
  42. else if (a[j].sc <= tt + t)
  43. tans++;
  44. else if (a[j].sc > tt + t)
  45. tans--;
  46. ans = max(ans, tans);
  47. }
  48. }
  49. cout << ans;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement