fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. ll s(ll a,ll b,ll c,ll d,ll n){
  9. ll w=b-a+1;
  10. ll h=d-c+1;
  11. if(w*d<n) return min((w+1)*d,w*(d+1));
  12. return w*d;
  13. }
  14.  
  15. void solve() {
  16. ll n;
  17. cin >> n;
  18. vector<pair<ll,int>> x(n), y(n);
  19. for(int i = 0; i < n; i++) {
  20. cin >> x[i].first >> y[i].first;
  21. x[i].second = y[i].second = i;}
  22. if(n==1){
  23. cout << 1 << '\n';
  24. return;
  25. }
  26. sort(x.begin(),x.end());
  27. sort(y.begin(),y.end());
  28. ll ans = s(x[0].first,x[n-1].first,y[0].first,y[n-1].first,n);
  29. int a[]={x[0].second,x[n-1].second,y[0].second,y[n-1].second};
  30. for(int i=0;i<4;i++){
  31. ll mnx = a[i]==x[0].second ? x[1].first :x[0].first;
  32. ll mxx = a[i]==x[n-1].second ? x[n-2].first : x[n-1].first;
  33. ll mny = a[i]==y[0].second ? y[1].first : y[0].first;
  34. ll mxy = a[i]==y[n-1].second ? y[n-2].first : y[n-1].first;
  35. ans=min(ans,s(mnx,mxx,mny,mxy,n));
  36. }
  37. cout << ans << '\n';
  38. }
  39.  
  40. int main(){
  41. ios::sync_with_stdio(false);
  42. cin.tie(nullptr);
  43.  
  44. int t;
  45. cin >> t;
  46. while (t--) solve();
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5320KB
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