#include <bits/stdc++.h>
using namespace std;
const int MAXN = 112345;
vector <double> v1, v2;
double s[MAXN];
bool cmp(double a, double b) {
return a > b;
}
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
double a, b;
cin >> a >> b;
v1.push_back(a); v2.push_back(b);
}
sort(v1.begin(), v1.end(), cmp); sort(v2.begin(), v2.end(), cmp);
s[0] = v2[0];
for(int i = 1; i < n; i++) {
s[i] = s[i - 1] + v2[i];
}
double resp = 0;
double sum = 0;
for(int i = 0; i < n; i++) {
sum += v1[i];
int ini = 0, fim = n - 1;
while(ini < fim) {
int m = (ini + fim) / 2;
if(ini == fim - 1) m = fim;
double val1 = sum - m - 1 - i - 1, val2 = s[m] - m - 1 - i - 1;
if(val1 < val2) {
fim = m - 1;
}
else ini = m;
}
//printf("%d %d\n", i + 1, ini + 1);
double val1 = sum - ini - 1 - i - 1, val2 = s[ini] - ini - 1 - i - 1;
//printf("%lf %lf\n", val1, val2);
resp = max(resp, min(val1, val2));
val1 = val1 - 1; val2 = val2 - s[ini] + s[ini + 1] - 1;
resp = max(resp, min(val1, val2));
}
printf("%.4lf\n", resp);
return 0;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 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 |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 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 |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
231 ms |
4328 KB |
Output is correct |
18 |
Correct |
232 ms |
4324 KB |
Output is correct |
19 |
Correct |
229 ms |
4196 KB |
Output is correct |
20 |
Correct |
229 ms |
4304 KB |
Output is correct |
21 |
Correct |
263 ms |
4708 KB |
Output is correct |
22 |
Correct |
228 ms |
4196 KB |
Output is correct |
23 |
Correct |
229 ms |
4344 KB |
Output is correct |
24 |
Correct |
232 ms |
4320 KB |
Output is correct |
25 |
Correct |
229 ms |
4320 KB |
Output is correct |
26 |
Correct |
268 ms |
4756 KB |
Output is correct |