#include <bits/stdc++.h>
using namespace std;
#define ar array< int , 2>
#define MASK(i) (1 << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
const int MAX = 1e5 + 1000;
double n, a[MAX], b[MAX], ans, x, y;
bool Compare(double a, double b)
{
return a >= b;
}
vector< double > A, B;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
A.push_back(LONG_MAX);
B.push_back(LONG_MAX);
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
A.push_back(a[i]);
B.push_back(b[i]);
}
sort(A.begin(), A.end(), Compare);
sort(B.begin(), B.end(), Compare);
//for (double i : A) cout << i << '\n' ;
double sum1 = A[1], sum2 = B[1], sum3 = 2.0;
int i1 = 2, i2 = 2;
while (true)
{
ans = max(ans, min(sum1 - sum3, sum2 - sum3));
if (sum1 - sum3 < 0 && i1 <= n)
{
sum1 += A[i1];
i1++;
sum3 += 1.0;
}
else
if (sum2 - sum3 < 0 && i2 <= n)
{
sum2 += B[i2];
i2++;
sum3 += 1.0;
}
else
if (sum1 < sum2 && i1 <= n)
{
sum1 += A[i1];
i1++;
sum3 += 1.0;
}
else
if (sum1 > sum2 && i2 <= n)
{
sum2 += B[i2];
i2++;
sum3 += 1.0;
}
else
if (sum1 == sum2 && i1 <= n && i2 <= n)
{
sum1 += A[i1];
i1++;
sum3 += 1.0;
sum2 += B[i2];
i2++;
sum3 += 1.0;
} else break;
}
printf("%.4lf",(double)ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
79 ms |
3700 KB |
Output is correct |
18 |
Correct |
85 ms |
3632 KB |
Output is correct |
19 |
Correct |
75 ms |
3568 KB |
Output is correct |
20 |
Correct |
75 ms |
3780 KB |
Output is correct |
21 |
Correct |
83 ms |
3636 KB |
Output is correct |
22 |
Correct |
81 ms |
3568 KB |
Output is correct |
23 |
Correct |
78 ms |
3664 KB |
Output is correct |
24 |
Correct |
81 ms |
3556 KB |
Output is correct |
25 |
Correct |
80 ms |
3648 KB |
Output is correct |
26 |
Correct |
97 ms |
3592 KB |
Output is correct |