This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<double, double> pdd;
void print() {cerr << '\n';} template <typename T1, typename... T2>
void print(const T1 &a, const T2 &...b) { cerr << a << ' ', print(b...); }
const int N = 1e5;
const int mod = 1e9 + 7;
double a[N], b[N];
double res = 0;
int n;
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
sort(a + 1, a + 1 + n, greater<double>());
sort(b + 1, b + 1 + n, greater<double>());
int i = 0, j = 0;
double sa = 0, sb = 0;
while(true)
{
if(i > n && j > n) break;
if(j > n)
sa += a[++i];
else if(i > n)
sb += b[++j];
else if(sa < sb)
sa += a[++i];
else
sb += b[++j];
res = max(res, min(sa, sb) - i - j);
}
cout << setprecision(4) << fixed << res;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
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... |