fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void f() {
  5. long long n;
  6. cin >> n;
  7. vector<long long> a(n), b(n);
  8. multiset<long long> xx, yy;
  9.  
  10. for (long long i = 0; i < n; i++) {
  11. cin >> a[i] >> b[i];
  12. xx.insert(a[i]);
  13. yy.insert(b[i]);
  14. }
  15.  
  16. if (n <= 2){
  17. cout << n << '\n';
  18. return;
  19. }
  20. long long ans = LLONG_MAX;
  21.  
  22. for (long long i = 0; i < n; i++) {
  23. xx.erase(xx.find(a[i]));
  24. yy.erase(yy.find(b[i]));
  25.  
  26. long long w = *xx.rbegin() - *xx.begin() + 1;
  27. long long h = *yy.rbegin() - *yy.begin() + 1;
  28.  
  29. if (w * h == n - 1) {
  30. ans = w * h + min(w, h);
  31. } else {
  32. ans = min(ans, w * h);
  33. }
  34.  
  35. xx.insert(a[i]);
  36. yy.insert(b[i]);
  37. }
  38.  
  39. cout << ans << '\n';
  40. }
  41.  
  42. int main() {
  43. ios::sync_with_stdio(false);
  44. cin.tie(0);
  45. long long t;
  46. cin >> t;
  47. while (t--) {
  48. f();
  49. }
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5292KB
stdin
7
3
1 1
1 2
2 1
5
1 1
2 6
6 4
3 3
8 2
4
1 1
1 1000000000
1000000000 1
1000000000 1000000000
1
1 1
5
1 2
4 2
4 3
3 1
3 2
3
1 1
2 5
2 2
4
4 3
3 1
4 4
1 2
stdout
3
32
1000000000000000000
1
6
4
8