#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(52);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename V>
using table = gp_hash_table<T, V>;
using i128 = __int128;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
const ll INF = 2e18;
const int inf = 2e9;
const int maxn = 1e5;
const int MOD = 988244353;
const ld pi = acos(-1);
const int P = 5167;
const int L = 26;
const ld EPS = 1e-7;
template<typename T, typename V>
void fill(T &container, V value) {
for (auto &c: container)
c = value;
}
#define int ll
pair<ld, ld> pls(pair<ld, ld> a, pair<ld, ld> b) {
return {a.first + b.first, a.second + b.second};
}
void solve() {
int n;
cin >> n;
vector<pair<ld, ld> > A(n);
for (int i = 0; i < n; ++i) cin >> A[i].first >> A[i].second;
for (int i = 0; i < n; ++i) {
A[i].first--;
A[i].second--;
}
sort(A.rbegin(), A.rend());
pair<ld, ld> a = {-1, A[0].second}, b = {-1, A[0].first};
for (int i = 1; i < n; ++i) {
auto [x, y] = A[i];
vector<pair<ld, ld> > v(4);
v[0] = pls(a, make_pair(x, -1));
v[1] = pls(a, make_pair(-1, y));
v[2] = pls(b, make_pair(y, -1));
v[3] = pls(b, make_pair(-1, x));
for (int j = 0; j < 2; ++j) {
if (v[j].first <= v[j].second) {
a = max(a, v[j]);
}
if (v[j].second <= v[j].first) {
swap(v[j].first, v[j].second);
b = max(b, v[j]);
}
}
for (int j = 2; j < 4; ++j) {
if (v[j].first <= v[j].second) {
b = max(b, v[j]);
}
if (v[j].second <= v[j].first) {
swap(v[j].first, v[j].second);
a = max(a, v[j]);
}
}
}
cout << abs(max(a.first, b.first));
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(4);
int t = 1;
//cin >> t;
while (t--) solve();
//stress();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |