이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
using ld = long double;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<ld> a(n + 1), b(n + 1);
a[0] = b[0] = 1e6;
rep(i, 0, n) cin >> a[i + 1] >> b[i + 1];
sort(rall(a)); sort(rall(b));
a[0] = b[0] = 0;
rep(i, 0, n) a[i + 1] += a[i], b[i + 1] += b[i];
auto f = [&](int x, int y) -> ld {
return min(a[x], b[y]) - x - y;
};
ld ans = 0;
rep(x, 0, n + 1) {
int l = 0, r = n;
while (r - l >= 5) {
int mid = l + (r - l) / 2;
if (f(x, mid) < f(x, mid + 1))
l = mid;
else r = mid + 1;
}
rep(i, l + 1, r + 1) if (f(x, l) < f(x, i)) l = i;
ans = max(ans, f(x, l));
}
cout << fixed << setprecision(4) << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |