#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <time.h>
#include <stack>
#include <queue>
#include <random>
#include <fstream>
#define endl '\n'
#define flush fflush(stdout), cout.flush()
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
const ll hs = 199;
const ldb eps = 1e-9, pi = acos(-1);
using namespace std;
int n;
vector<double> a, b;
double mx = 0;
bool cmp(double x, double y) {
return x > y;
}
int main() {
cin >> n;
a.resize(n);
b.resize(n);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
int nxt1 = 0, nxt2 = 0;
double v1 = 0, v2 = 0;
for (int tot = 1; tot <= 2 * n; tot++) {
if (nxt1 == n) v2 += b[nxt2++];
else if (nxt2 == n) v1 += a[nxt1++];
else if (v1 > v2) v2 += b[nxt2++];
else v1 += a[nxt1++];
mx = max(mx, min(v1, v2) - tot);
}
printf("%.4lf", (double)mx);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
360 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
360 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
488 KB |
Output is correct |
7 |
Correct |
2 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
568 KB |
Output is correct |
10 |
Correct |
2 ms |
568 KB |
Output is correct |
11 |
Correct |
2 ms |
568 KB |
Output is correct |
12 |
Correct |
4 ms |
792 KB |
Output is correct |
13 |
Correct |
4 ms |
792 KB |
Output is correct |
14 |
Correct |
4 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
5 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
360 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
488 KB |
Output is correct |
7 |
Correct |
2 ms |
508 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
568 KB |
Output is correct |
10 |
Correct |
2 ms |
568 KB |
Output is correct |
11 |
Correct |
2 ms |
568 KB |
Output is correct |
12 |
Correct |
4 ms |
792 KB |
Output is correct |
13 |
Correct |
4 ms |
792 KB |
Output is correct |
14 |
Correct |
4 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
5 ms |
792 KB |
Output is correct |
17 |
Correct |
175 ms |
3080 KB |
Output is correct |
18 |
Correct |
215 ms |
4472 KB |
Output is correct |
19 |
Correct |
206 ms |
4692 KB |
Output is correct |
20 |
Correct |
192 ms |
4732 KB |
Output is correct |
21 |
Correct |
264 ms |
4732 KB |
Output is correct |
22 |
Correct |
200 ms |
4732 KB |
Output is correct |
23 |
Correct |
197 ms |
4732 KB |
Output is correct |
24 |
Correct |
198 ms |
4764 KB |
Output is correct |
25 |
Correct |
191 ms |
4764 KB |
Output is correct |
26 |
Correct |
228 ms |
4764 KB |
Output is correct |