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 <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define double long double
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n;
double a[ 100001 ], b[ 100001 ];
vector <double> v, vv;
double f( int mask, int o, double sum, double ans, double col ) {
double mxx = min( sum - col, ans - col );
for ( int i = o; i < n; i ++ ) {
if ( !( mask & ( 1 << i ) ) ) {
mask |= ( 1 << i );
col ++;
sum += a[ i ];
mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
sum -= a[ i ];
ans += b[ i ];
mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
col --;
ans -= b[ i ];
col += 2;
ans += b[ i ];
sum += a[ i ];
mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
col -= 2;
ans -= b[ i ];
sum -= a[ i ];
mask ^= ( 1 << i );
}
}
return mxx;
}
double p[ 100001 ];
int main () {
cin >> n;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ] >> b[ i ];
v.push_back( a[ i ] );
vv.push_back( b[ i ] );
}
sort( v.begin(), v.end() );
sort( vv.begin(), vv.end() );
reverse( v.begin(), v.end() );
reverse( vv.begin(), vv.end() );
for ( int i = 0; i < vv.size(); i ++ )
p[ i + 1 ] = vv[ i ] + p[ i ];
double sum, num, ans, mx;
sum = num = ans = mx = 0;
int l, r, mid;
for ( int i = 0; i < v.size(); i ++ ) {
sum += v[ i ];
ans = i + 1;
mx = max( mx, min( sum - ans, -ans ) );
l = 1;
r = vv.size();
while ( r - l > 1 ) {
mid = ( r + l ) / 2;
ans = mid + i + 1;
if ( sum < ans ) {
r = mid - 1;
}
else {
if ( sum - ans < p[ mid ] - ans ) {
r = mid - 1;
}
else
l = mid;
}
}
ans = l + i + 1;
mx = max( mx, min( p[ l ] - ans, sum - ans ) );
num = 0;
}
cout << fixed << setprecision(4) << mx;
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for ( int i = 0; i < vv.size(); i ++ )
| ~~^~~~~~~~~~~
sure.cpp:94:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for ( int i = 0; i < v.size(); i ++ ) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |