#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }
struct Vec {
ll x, y;
Vec(ll _x = 0, ll _y = 0) : x(_x), y(_y) {}
Vec operator-(Vec o) {
return Vec(x - o.x, y - o.y);
}
bool operator<(Vec o) {
return (x < o.x || (x == o.x && y < o.y));
}
};
using Point = Vec;
ll cross(Vec a, Vec b) {
return (a.x * b.y) - (a.y * b.x);
}
bool ccw(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) > 0;
}
bool cw(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) < 0;
}
bool chk(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) < 0;
}
ll area(Point a, Point b, Point c) {
array<Point, 4> e;
e[0] = a; e[1] = b, e[2] = c, e[3] = a;
ll ans = 0;
for (int i = 0; i < 3; i++) {
ans += (e[i].x * e[i+1].y) - (e[i+1].x * e[i].y);
}
return abs(ans);
}
const int MAXN = 3e5 + 5;
Point a[MAXN], d[MAXN];
int main() {
#define NAME "test"
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> d[i].x >> d[i].y;
int m; cin >> m;
for (int i = 1; i <= m; i++) cin >> a[i].x >> a[i].y;
// reverse(d + 1, d + n + 1);
sort(a + 1, a + m + 1);
vector<Point> hull;
if (m < 3) {
for (int i = 1; i <= m; i++) hull.emplace_back(a[i]);
} else {
for (int i = 1; i <= m; i++) {
while ((int)hull.size() >= 2 && chk(hull[(int)hull.size() - 2], hull[(int)hull.size() - 1], a[i])) hull.pop_back();
hull.emplace_back(a[i]);
}
int sz = hull.size();
for (int i = m - 1; i >= 1; i--) {
while ((int)hull.size() >= sz + 1 && chk(hull[(int)hull.size() - 2], hull[(int)hull.size() - 1], a[i])) hull.pop_back();
hull.emplace_back(a[i]);
}
/// CCW
hull.pop_back();
}
int cur = 0, tt = 0;
m = hull.size();
if (m != 1) {
for (int i = 0; i < m; i++) {
if (ccw(d[0], hull[i], hull[(i + 1) % m])) {
cur = i;
break;
}
}
}
ll s = 0;
for (int i = 2; i < n; i++) {
if (cw(d[0], hull[cur], d[i])) {
s += area(d[0], d[i - 1], d[i]);
tt = i;
} else break;
}
ll ans = s;
tt++;
for (int i = 1; i < n; i++) {
if (m != 1) {
while (!ccw(d[i], hull[cur], hull[(cur + 1) % m])) {
cur++;
if (cur >= m) cur -= m;
}
}
s -= area(d[(i - 1 + n) % n], d[(tt - 1 + n) % n], d[i]);
if (tt == i) tt = (tt + 1) % n;
while (cw(d[i], hull[cur], d[tt])) {
s += area(d[tt], d[(tt - 1 + n) % n], d[i]);
tt++;
tt %= n;
}
ckmax(ans, s);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
sir.cpp: In function 'int main()':
sir.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sir.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |