이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |