이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
template<typename T>
bool ckmn(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template<typename T>
bool ckmx(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
const int N = 100001, infI = 1e9 + 7;
const ll infL = 3e18;
double a[N], b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
sort(a, a + n, greater<>());
sort(b, b + n, greater<>());
double ans = 0, suma = 0, sumb = 0;
vector<tuple<double, int, int>> v(2 * n);
for (int i = 0; i < n; ++i) {
suma += a[i];
sumb += b[i];
v[i] = {suma, i + 1, 0};
v[i + n] = {sumb, i + 1, 1};
}
sort(all(v));
int mn[2] = {infI, infI};
for (int i = 2 * n - 1; i > -1; --i) {
ckmx(ans, get<0>(v[i]) - get<1>(v[i]) - mn[get<2>(v[i]) ^ 1]);
ckmn(mn[get<2>(v[i])], get<1>(v[i]));
}
cout << fixed << setprecision(4) << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |