이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define endl '\n'
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100005
#define mod 1000000007
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<double> a(n);
vector<double> b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
vector<double> pref(n + 1, 0);
for (int i = 0; i < n; i++)
{
pref[i + 1] = pref[i] + b[i];
}
double ans = 0.0, luc = 0, qt = 0.0;
for (int i = 0; i < n; i++)
{
luc += a[i];
qt += 1;
auto f = [&](int x)
{
return min(pref[x] - (qt + x), luc - (qt + x));
};
int l = 1, r = n;
while (l < r)
{
int mid = (l + r) >> 1;
(f(mid) > f(mid + 1)) ? r = mid : l = mid + 1;
}
ans = max(ans, f(l));
}
cout << fixed << setprecision(4) << ans << endl;
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... |