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;
using ll = long long;
int n;
vector<double> a, b;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for ( int i=0; i<n; i++ )
{
double dl, dr;
cin >> dl >> dr;
a.push_back( dl );
b.push_back( dr );
}
sort( a.begin(), a.end(), greater<double>() );
sort( b.begin(), b.end(), greater<double>() );
/*for ( auto& el : a )
cout << el << ' ';
cout << '\n';
for ( auto& el : b )
cout << el << ' ';
cout << '\n';*/
double ans = 0;
double cur1 = 0;
double cur2 = 0;
int j = -1;
for ( int i=0; i<n; i++ )
{
cur1 += a[i];
while ( j+1 < n && min( cur1 - ( i+1 + j+1 ), cur2 - ( i+1 + j+1 ) ) < min( cur1 - ( i+1 + j+2 ), cur2+b[j+1] - ( i+1 + j+2 ) ) )
{
j++;
cur2 += b[j];
}
//cout << "for " << i << " - " << j << ": " << cur1 << ' ' << cur2 << ' ' << min( cur1 - ( i+1 + j+1 ), cur2 - ( i+1 + j+1 ) ) << '\n';
ans = max( ans, min( cur1 - ( i+1 + j+1 ), cur2 - ( i+1 + j+1 ) ) );
}
cout << fixed << setprecision(4);
cout << ans;
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... |