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 FILE_IO
int N;
double a[100005], b[100005];
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
cin >> N;
for(int i = 1; i <= N; i++)
cin >> a[i] >> b[i];
sort(a + 1, a + N + 1); reverse(a + 1, a + N + 1);
sort(b + 1, b + N + 1); reverse(b + 1, b + N + 1);
int p1 = 1, p2 = 1;
double prfA = 0.0, prfB = 0.0;
double ans = 0.0;
int cnt = 0;
while(p1 <= N || p2 <= N)
{
if(prfA < prfB && p1 <= N)
{
prfA += a[p1];
p1++;
cnt++;
}
else if(p2 <= N)
{
prfB += b[p2];
p2++;
cnt++;
}
else
break;
ans = max(ans, min(prfA, prfB) - cnt);
}
cout << fixed << setprecision(4) << ans << '\n';
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... |