#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
int main()
{
int N; cin >> N;
vector<double> a(N);
vector<double> b(N);
for (int n = 0; n < N; ++n)
{
double av, bv; cin >> av >> bv;
a[n] = av;
b[n] = bv;
}
auto comp = [](const double& ta, const double& tb){return ta > tb;};
sort(a.begin(), a.end(), comp);
sort(b.begin(), b.end(), comp);
int totalPicked = 0;
int indexA = 0;
int indexB = 0;
double sumA = 0;
double sumB = 0;
double bestAnswer = 0.0;
while (true)
{
if (sumA < sumB)
{
if (indexA >= (int)a.size()) break;
sumA += a[indexA];
indexA++;
}
else
{
if (indexB >= (int)b.size()) break;
sumB += b[indexB];
indexB++;
}
totalPicked++;
bestAnswer = max(bestAnswer, min(sumA - totalPicked, sumB - totalPicked));
}
printf("%.4lf", (double)bestAnswer);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
214 ms |
1944 KB |
Output is correct |
18 |
Correct |
210 ms |
1920 KB |
Output is correct |
19 |
Correct |
209 ms |
2040 KB |
Output is correct |
20 |
Correct |
212 ms |
2040 KB |
Output is correct |
21 |
Correct |
240 ms |
1920 KB |
Output is correct |
22 |
Correct |
212 ms |
2040 KB |
Output is correct |
23 |
Correct |
212 ms |
2044 KB |
Output is correct |
24 |
Correct |
215 ms |
1920 KB |
Output is correct |
25 |
Correct |
215 ms |
2040 KB |
Output is correct |
26 |
Correct |
245 ms |
2040 KB |
Output is correct |