fork(2) download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define mp make_pair
  4. #define pb push_back
  5. #define ff first
  6. #define ss second
  7. #define pii pair<int,int>
  8. #define mod 998244353
  9. #define endl '\n'
  10. #define f(i,a,b) for(i=a;i<b;i++)
  11. #define MAX(a,b,c) max(a,max(b,c))
  12. #define MIN(a,b,c) min(a,min(b,c))
  13. #define PI 3.1415926535897932
  14. #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  15. #define input_file freopen("op.txt", "r", stdin);
  16. #define output_file freopen("op1.txt", "w", stdout);
  17. using namespace std;
  18.  
  19. int main(){
  20. fast_io
  21.  
  22. int i,j,x,n;
  23. cin>>n;
  24. int a[n],e[n];
  25. f(i,0,n){
  26. cin>>a[i]>>x;
  27. e[i] = a[i] + x;
  28. }
  29.  
  30. sort(a,a+n);
  31. sort(e,e+n);
  32.  
  33. i = 1;
  34. j = 0;
  35.  
  36. int cnt=1,mt=1,t=a[0];
  37.  
  38. while(i<n && j<n){
  39. if(a[i] <= e[j]){
  40. cnt++;
  41. if(cnt > mt){
  42. mt = cnt;
  43. t = a[i];
  44. }
  45. i++;
  46. }
  47. else{
  48. cnt--;
  49. j++;
  50. }
  51. }
  52.  
  53. cout<<mt;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 4392KB
stdin
3
10 2
5 10
13 2
stdout
2