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;
const int k_N = 1e5 + 3;
double a[k_N], b[k_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
sort(a, a + n, greater<double>());
sort(b, b + n, greater<double>());
double curr_a = 0, curr_b = 0, answer = 0;
int i = 0, j = 0;
while(i != n && j != n){
if(curr_a < curr_b)
curr_a += a[i], i++;
else
curr_b += b[j], j++;
answer = max(min(curr_a, curr_b) - i - j, answer);
}
while(i != n){
curr_a += a[i], i++;
answer = max(min(curr_a, curr_b) - i - j, answer);
}
while(j != n){
curr_b += b[j], j++;
answer = max(min(curr_a, curr_b) - i - j, answer);
}
cout << fixed << setprecision(4) << answer << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |