#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
int n;
long double a[mx], b[mx];
long double ans = 0;
long double sa = 0;
long double d[mx];
int main() {
cin.tie(0);ios::sync_with_stdio(0);
cin >> n;
for (int i=0;i<n;i++) {
cin >> a[i] >> b[i];
}
sort(a, a+n); reverse(a, a+n);
sort(b, b+n); reverse(b, b+n);
d[0] = b[0];
for (int i=1;i<n;i++) {
d[i] = d[i-1] + b[i];
}
for (int i=0;i<n;i++) {
sa += a[i];
if (a[i] <= 1) break;
long double sb = 0;
// for (int j=0;j<n;j++) {
// cout << sa - i - j - 2 << " ";
// }
// cout << "\n";
int lc = 0, rc = n-1;
while (lc < rc) {
int m = lc + rc >> 1;
if ((sa - i - m - 2) < (d[m] - i - m - 2)) {
rc = m;
} else {
lc = m+1;
}
}
// cout << lc << " ";
long double tmp;
tmp = sa - i - lc - 2;
if ( lc != 0 ) {
tmp = max(tmp, d[lc-1] - i - lc - 1);
}
ans = max(ans, tmp);
}
// cout << "\n";
cout << fixed << setprecision(4) << ans << "\n";
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:34:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int m = lc + rc >> 1;
| ~~~^~~~
sure.cpp:27:15: warning: unused variable 'sb' [-Wunused-variable]
27 | long double sb = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |