fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. void solve(){
  6. int n; cin >> n;
  7. vector<int> a(n), b(n);
  8. for(int i = 0; i < n; i++) {
  9. int x,y;cin>> x >> y;
  10. a[i]=x;
  11. b[i]=y;
  12. }
  13. if(n == 1) {
  14. cout << 1 << endl;
  15. return;
  16. }
  17. int ans = LLONG_MAX;
  18. for(int i = 0; i < n; i++) {
  19. int mna = 1e10, mxa = -1, mnb = 1e10, mxb = -1;
  20. for(int j = 0; j < n; j++) {
  21. if(i == j) continue;
  22. if(a[j] < mna) mna = a[j];
  23. if(a[j] > mxa) mxa = a[j];
  24. if(b[j] < mnb) mnb = b[j];
  25. if(b[j] > mxb) mxb = b[j];
  26. }
  27. int row = mxa - mna + 1;
  28. int col = mxb - mnb + 1;
  29. int rec = row * col;
  30. if(rec>n-1) ans = min(ans, rec);
  31. else ans = min(ans, rec+min(row,col));
  32. }
  33. cout << ans << endl;
  34. }
  35.  
  36. int32_t main() {
  37. ios::sync_with_stdio(false);
  38. cin.tie(nullptr);
  39. int t; cin >> t;
  40. while(t--) solve();
  41. }
Success #stdin #stdout 0.01s 5324KB
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