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;
int n;
vector<double> a, b;
bool srt(double x, double y) {
if(x == 0) return true;
if(y == 0) return false;
return x > y;
}
int main() {
cin >> n;
a = vector<double>(n + 1), b = vector<double>(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
sort(a.begin(), a.end(), srt);
sort(b.begin(), b.end(), srt);
for(int i = 1; i <= n; i++) {
a[i] += a[i - 1];
b[i] += b[i - 1];
}
//
double res = 0;
for(int i = 0; i <= n; i++) {
int l = 0, r = n + 1, mid, ans;
while(l<=r) {
mid = (l + r) / 2;
if(b[mid] <= a[i]) {
ans = mid;
l = mid + 1;
} else r = mid - 1;
}
res = max(res, min(a[i], b[ans]) - i - ans);
if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1);
//cout << i << " " << ans << " " << res << "\n";
}
for(int i = 0; i <= n; i++) {
int l = 0, r = n + 1, mid, ans;
while(l<=r) {
mid = (l + r) / 2;
if(a[mid] <= b[i]) {
ans = mid;
l = mid + 1;
} else r = mid - 1;
}
res = max(res, min(b[i], a[ans]) - i - ans);
if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1);
//cout << i << " " << ans << " " << res << "\n";
}
cout << fixed << setprecision(4) << res << "\n";
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:49:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1);
sure.cpp:36:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1);
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |