#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<double> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i]>>b[i];
}
sort(a.begin() + 1, a.end(), greater<double>());
sort(b.begin() + 1, b.end(), greater<double>());
vector<double> mx(n + 1);
for (int i = 1; i <= n; i++){
a[i] += a[i - 1];
b[i] += b[i - 1];
mx[i] = max(mx[i - 1], (b[i] - i));
}
vector<double> :: iterator it;
double out = 0;
for (int i = 1; i <= n; i++){
it = lower_bound(b.begin() + 1, b.end(), a[i]);
int j = (int) (it - b.begin());
if (j <= n) out = max(out, a[i] - (i + j));
if (j > 1) out = max(out, mx[j - 1] - i);
}
printf("%.4lf", out);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |