fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. struct item {
  5. ll x,y,z;
  6. };
  7. bool comp(item item1, item item2){
  8. if (item1.y!=item2.y){
  9. return item1.y<item2.y;
  10. }
  11. if (item1.x!=item2.x){
  12. return item1.x<item2.x;
  13. }
  14. return item1.z<item2.z;
  15. }
  16. int main() {
  17. // your code goes here
  18. ll n;
  19. cin>>n;
  20. vector <item> a(n);
  21. for (ll i=0;i<n;i++){
  22. ll t;
  23. cin>>a[i].x>>t;
  24. a[i].y=t+a[i].x;
  25. a[i].z=i;
  26. }
  27. sort(a.begin(),a.end(),comp);
  28. ll ans=0,max=a[0].x;
  29. for (ll i=0;i<n;i++){
  30. if (max<=a[i].x){
  31. ans++;
  32. max=a[i].y;
  33. }
  34. }
  35. cout<<ans;
  36. return 0;
  37. }
Success #stdin #stdout 0s 4220KB
stdin
5
1 2
2 3
1 2
3 1
3 2
stdout
2