Here’s the Problem
At first it seems reasonable that this problem possibly have solution like this, but it does not even pass the sample case
Please share your insights related to this problem
My Implementation
int n; cin >> n;
vector<array<long long, 2>> va(n);
for (int i = 0; i < n; i++) cin >> va[i][0] >> va[i][1];
sort(all(va));
vector<long long> prfs(n + 1, 0), suf(n + 1, 0);
long long a = va[0][0], b = va[0][1], c = va[0][0], d = va[0][1];
for (int i = 0; i < n; i++){
a = min(a, va[i][0]);
c = max(c, va[i][0]);
b = min(b, va[i][1]);
d = max(d, va[i][1]);
prfs[i] = (c - a) * (d - b);
}
a = va[n - 1][0], b = va[n - 1][1], c = va[n - 1][0], d = va[n - 1][1];
for (int i = n - 1; i >= 0; --i){
a = min(a, va[i][0]);
c = max(c, va[i][0]);
b = min(b, va[i][1]);
d = max(d, va[i][1]);
suf[i] = (c - a) * (d - b);
}
long long ans = 1e18;
for (int i = 0; i < n - 1; i++){
ans = min(prfs[i] + suf[i + 1], ans);
}
cout << ans;
Edit 1 : Official analysis solution of this problem is beyond my understanding yet. Could someone explain me in easy way… thank-you.