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>
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
using namespace std;
signed main()
{
int n;
cin>>n;
vector<double>a(n),b(n);
rep(i,n) cin>>a[i]>>b[i];
sort(all(a));
sort(all(b));
reverse(all(a));
reverse(all(b));
double maxx = 0;
int off = 2;
vector<double>sum(2);
vector<int>point(2,1);
sum[0] = a[0];
sum[1] = b[0];
while(max(point[0], point[1])<n)
{
maxx=max(maxx, min(sum[0], sum[1])-off);
if(sum[0]>sum[1]) {sum[1]+=b[point[1]]; point[1]++;}
else {sum[0]+=a[point[0]]; point[0]++;}
off++;
}
printf("%.4lf",(double)maxx);
cout<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |