//
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vvi vector< vi >
#define vii vector< ii >
#define mp make_pair
#define pb push_back
const int maxn = 1e5+5;
double A[maxn], B[maxn];
int n;
double solve(int k)
{
int lo = max(0, k-n), hi = min(n, k);
double best = -1e9;
while(lo<= hi)
{
int mid = (lo+hi)/2;
//printf("%d %d\n", lo, hi);
double x = A[mid];
double y = B[k-mid];
//printf("%.4lf %.4lf\n", x, y);
if(x == y) return x;
best = max(best, min(x, y));
if(x< y) lo = mid+1;
else hi = mid-1;
}
//printf("%d: %.4lf\n", k, best);
return best;
}
int main()
{
//#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
scanf("%d", &n);
for(int i = 1; i<= n; i++)
{
cin >> A[i] >> B[i];
}
sort(A+1, A+n+1); sort(B+1, B+n+1);
reverse(A+1, A+n+1); reverse(B+1, B+n+1);
for(int i = 1; i<= n; i++)
{
A[i] += A[i-1]; B[i] += B[i-1];
//cout << A[i] << " " << B[i] << endl;
}
double best = 0;
for(int i = 1; i<= 2*n; i++) best = max(best, solve(i)-i);
printf("%.4lf\n", best);
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
380 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
380 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
380 KB |
Output is correct |
17 |
Correct |
203 ms |
3224 KB |
Output is correct |
18 |
Correct |
203 ms |
3172 KB |
Output is correct |
19 |
Correct |
203 ms |
3264 KB |
Output is correct |
20 |
Correct |
204 ms |
3192 KB |
Output is correct |
21 |
Correct |
235 ms |
3644 KB |
Output is correct |
22 |
Correct |
203 ms |
3192 KB |
Output is correct |
23 |
Correct |
203 ms |
3312 KB |
Output is correct |
24 |
Correct |
207 ms |
3256 KB |
Output is correct |
25 |
Correct |
204 ms |
3296 KB |
Output is correct |
26 |
Correct |
238 ms |
3576 KB |
Output is correct |