#include <bits/stdc++.h>
#define DIM 100010
using namespace std;
double a[DIM],b[DIM],sp_a[DIM],sp_b[DIM];
int n,i;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
for (i=1;i<=n;i++)
cin>>a[i]>>b[i];
sort (a+1,a+n+1);
reverse (a+1,a+n+1);
sort (b+1,b+n+1);
reverse (b+1,b+n+1);
for (i=1;i<=n;i++){
sp_a[i] = sp_a[i-1] + a[i];
sp_b[i] = sp_b[i-1] + b[i];
}
/// fixez cat iau din prima
double maxi = 0;
for (i=1;i<=n;i++){
double sum1 = sp_a[i] - i;
int st = 1, dr = n, sol = 0;
while (st <= dr){
int mid = (st+dr)>>1;
if (sum1-mid > 0 && sum1 - mid <= sp_b[mid] - i - mid){
sol = mid;
st = mid+1;
} else dr = mid-1;
}
if (sol)
maxi = max (maxi,sum1 - sol);
}
cout<<setprecision(4)<<fixed<<maxi;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |