fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <climits>
  4.  
  5. using namespace std;
  6.  
  7. struct Point
  8. {
  9. long long x;
  10. long long y;
  11.  
  12. Point(long long x ,long long y)
  13. {
  14. this->x = x;
  15. this->y = y;
  16. }
  17. };
  18.  
  19. int main()
  20. {
  21. int n;
  22. Point temp(0, 0);
  23. cin >> n;
  24.  
  25. // initial data
  26. Point tr(LONG_LONG_MIN, LONG_LONG_MIN); // top right
  27. Point tl(LONG_LONG_MAX, LONG_LONG_MIN); // top left
  28. Point br(LONG_LONG_MIN, LONG_LONG_MAX); // bottom right
  29. Point bl(LONG_LONG_MAX, LONG_LONG_MAX); // bottom left
  30.  
  31. while(n--)
  32. {
  33. cin >> temp.x >> temp.y;
  34.  
  35. if(temp.x <= tl.x && temp.y >= tl.y)
  36. tl = temp;
  37. if(temp.x >= tr.x && temp.y >= tr.y)
  38. tr = temp;
  39. if(temp.x <= bl.x && temp.y <= bl.y)
  40. bl = temp;
  41. if(temp.x >= br.x && temp.y <= br.y)
  42. br = temp;
  43. }
  44.  
  45. // distances
  46. long long d1 = abs(tr.x - bl.x) + abs(tr.y - bl.y);
  47. long long d2 = abs(tl.x - br.x) + abs(tl.y - br.y);
  48. long long d3 = abs(tl.x - tr.x) + abs(tl.y - tr.y);
  49. long long d4 = abs(bl.x - br.x) + abs(bl.y - br.y);
  50. long long d5 = abs(tl.x - bl.x) + abs(tl.y - bl.y);
  51. long long d6 = abs(tr.x - br.x) + abs(tr.y - br.y);
  52.  
  53. // biggest distance
  54. long long result = max(max(d1, d2), max(d3, d4));
  55. result = max(result, max(d5, d6));
  56.  
  57. cout << result << endl;
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 15240KB
stdin
5
2 3
5 2
0 1
-5 2
-2 3
stdout
8