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;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n;
cin >> n;
vector<double> a(n), b(n), prefix_b(n);
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i];
sort(a.begin(), a.end(), greater<double>());
sort(b.begin(), b.end(), greater<double>());
prefix_b[0] = b[0];
for(int i = 1; i < n; i++)
prefix_b[i] = prefix_b[i-1] + b[i];
double total_a = 0, total_max = 0;
for(int i = 0; i < n; i++){
total_a += a[i];
auto it = upper_bound(prefix_b.begin(), prefix_b.end(), total_a) - prefix_b.begin();
if(it != n)
total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2)));
it--;
if(it != -1)
total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2)));
}
cout << fixed << setprecision(4) << total_max << '\n';
}
int main(){
//freopen("flota.in", "r", stdin);
//freopen("flota.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |