Advertisement
Guest User

Ia ba

a guest
Nov 14th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin ("cerc3.in");
  8. ofstream fout ("cerc3.out");
  9.  
  10. struct cerc{
  11. int dreapta;
  12. int stanga;
  13. };
  14.  
  15. cerc v[1000];
  16.  
  17. bool comp(cerc a, cerc b)
  18. {
  19. return a.dreapta < b.dreapta;
  20. }
  21.  
  22. int main()
  23. {
  24. int n, i, x, y;
  25. fin >> n;
  26. for(i = 0; i < n; i++)
  27. {
  28. fin >> x >> y;
  29. v[i].dreapta = x + y;
  30. v[i].stanga = x - y;
  31. }
  32. sort(v, v + n, comp);
  33. int k = 1;
  34. int capat = v[0].dreapta;
  35. for(i = 1; i < n; i++)
  36. {
  37.  
  38. if(v[i].stanga > capat)
  39. {
  40. k++;
  41. capat = v[i].dreapta;
  42. }
  43. }
  44. fout << k << endl;
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement