fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define f first
  4. #define s second
  5. bool cmp(const pair<int, int> a, const pair<int, int> b){
  6.  
  7. if(a.f == b.f) return a.s > b.s;
  8.  
  9. return a.f < b.f;
  10.  
  11. }
  12. int main(){
  13. freopen("mountains.in", "r", stdin);
  14. freopen("mountains.out", "w", stdout);
  15. int n;
  16. cin >> n;
  17. vector<pair<int, int> > a;
  18. for(int i = 1;i <= n;i++){
  19. int x, y;
  20. cin >> x >> y;
  21. a.push_back({x - y, x + y});
  22. }
  23. sort(a.begin(), a.end(), cmp);
  24. int visible = 0;
  25. int r = -1;
  26. for(auto m : a){
  27. if(m.s > r){
  28. r = m.s;
  29. visible++;
  30. }
  31. }
  32. cout << visible << endl;
  33. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty