-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.cpp
80 lines (56 loc) · 1.65 KB
/
split.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
ll n;
bool ycmp(pi a, pi b) { return a.second < b.second; }
vi calc_psum_hor(vector<pi> a) {
// calc for horizontal line
ll leftmost, rightmost;
leftmost = rightmost = a[0].second;
vi psum_hor(n + 1);
for (ll i = 0; i < n; i++) {
leftmost = min(leftmost, a[i].second);
rightmost = max(rightmost, a[i].second);
ll area = abs(a[i].first - a[0].first) * abs(rightmost - leftmost);
psum_hor[i + 1] = area;
}
return psum_hor;
}
int main() {
ifstream fin("split.in");
ofstream fout("split.out");
fin >> n;
vector<pi> a(n);
for (ll i = 0; i < n; i++) {
fin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
ll one_width = a[n - 1].first - a[0].first;
sort(a.begin(), a.end(), ycmp);
ll one_height = a[n - 1].second - a[0].second;
sort(a.begin(), a.end());
ll one_area = one_width * one_height;
vi psum_hor = calc_psum_hor(a);
reverse(a.begin(), a.end());
vi ssum_hor = calc_psum_hor(a);
for (ll i = 0; i < n; i++) {
pi temp = a[i];
a[i].first = temp.second;
a[i].second = temp.first;
}
sort(a.begin(), a.end());
vi psum_ver = calc_psum_hor(a);
reverse(a.begin(), a.end());
vi ssum_ver = calc_psum_hor(a);
ll best = 1e18+4;
for (ll i = 1; i <= n; i++) {
best = min(best, psum_hor[i] + ssum_hor[n - i]);
}
for (ll i = 1; i <= n; i++) {
best = min(best, psum_ver[i] + ssum_ver[n - i]);
}
fout << one_area - best << endl;
return 0;
}