#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <double> a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
a[i]--;
b[i]--;
}
sort(all(a));sort(all(b));
reverse(all(a));reverse(all(b));
double ans=0;
double sum1=0,sum2=0;
int cnt=0;
for(int i=0;i<n;i++){
sum1+=a[i];
while(cnt<n && min(sum1-cnt,sum2-i-1)<=min(sum1-cnt-1,sum2+b[cnt]-i-1)){
sum2+=b[cnt];
cnt++;
}
ans=max(ans,min(sum1-cnt,sum2-i-1));
}
cout<<fixed<<setprecision(4)<<ans<<"\n";
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
90 ms |
1884 KB |
Output is correct |
18 |
Correct |
90 ms |
1988 KB |
Output is correct |
19 |
Correct |
91 ms |
1884 KB |
Output is correct |
20 |
Correct |
90 ms |
1880 KB |
Output is correct |
21 |
Correct |
100 ms |
2136 KB |
Output is correct |
22 |
Correct |
90 ms |
1884 KB |
Output is correct |
23 |
Correct |
104 ms |
1988 KB |
Output is correct |
24 |
Correct |
105 ms |
1880 KB |
Output is correct |
25 |
Correct |
92 ms |
2036 KB |
Output is correct |
26 |
Correct |
100 ms |
1988 KB |
Output is correct |