#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
template <class T>
void rd(T &x) {
int sgn = 1;
char ch;
x = 0;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
if (ch == '-') ch = getchar(), sgn = -1;
for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= sgn;
}
template <class T>
void wr(T x) {
if (x < 0) putchar('-'), wr(-x);
else if (x < 10) putchar(x + '0');
else wr(x / 10), putchar(x % 10 + '0');
}
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
int n;
double ans = 0;
vector<double> A, B;
int main() {
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
cin >> n;
rep(i, 1, n+1){
double a, b;
cin >> a >> b;
A.push_back(a);
B.push_back(b);
}
sort(A.begin(), A.end(), greater<double>());
sort(B.begin(), B.end(), greater<double>());
rep(i, 1, n){ A[i] += A[i-1]; B[i] += B[i-1]; }
rep(i, 1, 2*n+1){
double l = 0, r = 1e8;
while(r - l > 1e-5){
double mid = (l + r)/2;
int pos1 = lower_bound(A.begin(), A.end(), mid) - A.begin(), pos2 = lower_bound(B.begin(), B.end(), mid) - B.begin();
if(A.back() >= mid and B.back() >= mid and pos1 + pos2 + 2 <= i) l = mid;
else r = mid;
}
ans = max(ans, l - i);
}
printf("%.4f\n", ans);
}
Compilation message
sure.cpp: In function 'void usaco(std::string)':
sure.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
33 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
34 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
5 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
364 KB |
Output is correct |
14 |
Correct |
5 ms |
364 KB |
Output is correct |
15 |
Correct |
5 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
5 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
364 KB |
Output is correct |
14 |
Correct |
5 ms |
364 KB |
Output is correct |
15 |
Correct |
5 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
364 KB |
Output is correct |
17 |
Correct |
686 ms |
2136 KB |
Output is correct |
18 |
Correct |
708 ms |
2136 KB |
Output is correct |
19 |
Correct |
656 ms |
2136 KB |
Output is correct |
20 |
Correct |
627 ms |
2136 KB |
Output is correct |
21 |
Correct |
670 ms |
2136 KB |
Output is correct |
22 |
Correct |
646 ms |
2136 KB |
Output is correct |
23 |
Correct |
653 ms |
2136 KB |
Output is correct |
24 |
Correct |
647 ms |
2136 KB |
Output is correct |
25 |
Correct |
635 ms |
2168 KB |
Output is correct |
26 |
Correct |
671 ms |
2136 KB |
Output is correct |