#include<bits/stdc++.h>
using namespace std;
#define ld double
vector<ld> sa, sb;
ld ternary_search(int lo, int hi, ld a, int b) {
auto f = [&](int j){
return min(sb[j], a) - (b + j + 1);
};
while (hi - lo > 1){
int mid = (hi + lo)>>1;
if (f(mid) > f(mid + 1))
hi = mid;
else
lo = mid;
}
return f(lo + 1);
}
ld ternary_search2(int lo, int hi, int n) {
auto f = [&](int i){
return ternary_search(-1, n, sa[i], i + 1);
};
while (hi - lo > 1){
int mid = (hi + lo)>>1;
if (f(mid) > f(mid + 1))
hi = mid;
else
lo = mid;
}
return f(lo + 1);
}
int32_t main(){
cin.tie(NULL)->sync_with_stdio(false);
int n; cin >> n;
vector<ld> a, b;
for(int i = 0; i < n; ++i){
ld x, y; cin >> x >> y;
a.push_back(x);
b.push_back(y);
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
for(int i = 0; i < n; ++i){
sa.push_back(a[i]);
sb.push_back(b[i]);
if(i){
sa[i] += sa[i - 1];
sb[i] += sb[i - 1];
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
ld x = min(sa[i], sb[j]);
int y = i + j + 2;
}
}
ld ans = ternary_search2(-1, n, n);
cout << setprecision(4) << fixed << ans << "\n";
}
Compilation message
sure.cpp: In function 'int32_t main()':
sure.cpp:63:10: warning: unused variable 'x' [-Wunused-variable]
63 | ld x = min(sa[i], sb[j]);
| ^
sure.cpp:64:11: warning: unused variable 'y' [-Wunused-variable]
64 | int y = i + j + 2;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |