//
#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);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
360 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
360 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
139 ms |
3272 KB |
Output is correct |
18 |
Correct |
140 ms |
3320 KB |
Output is correct |
19 |
Correct |
137 ms |
3320 KB |
Output is correct |
20 |
Correct |
142 ms |
3292 KB |
Output is correct |
21 |
Correct |
157 ms |
3564 KB |
Output is correct |
22 |
Correct |
141 ms |
3368 KB |
Output is correct |
23 |
Correct |
138 ms |
3320 KB |
Output is correct |
24 |
Correct |
140 ms |
3192 KB |
Output is correct |
25 |
Correct |
141 ms |
3228 KB |
Output is correct |
26 |
Correct |
154 ms |
3724 KB |
Output is correct |