#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define fi first
#define se second
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compress(v) sort(all(v)), (v).erase(unique(all((v))), v.end())
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }
template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }
int main() {
int N;
scanf("%d", &N);
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) {
double a, b;
scanf("%lf %lf", &a, &b);
a *= 10000;
b *= 10000;
A[i] = (int)a;
B[i] = (int)b;
}
sort(all(A));
reverse(all(A));
sort(all(B));
reverse(all(B));
ll ans = 0;
ll Asum = 0, Bsum = 0;
int Aptr = 0, Bptr = 0;
for (int x = 1; x <= 2 * N; x++) {
if (Aptr == N) {
Bsum += B[Bptr++];
} else if (Bptr == N) {
Asum += A[Aptr++];
} else {
if (Asum == Bsum) {
if (A[Aptr] < B[Bptr]) {
Bsum += B[Bptr++];
} else {
Asum += A[Aptr++];
}
} else if (Asum > Bsum) {
Bsum += B[Bptr++];
} else {
Asum += A[Aptr++];
}
}
ans = max(ans, min(Asum, Bsum) - 1LL * x * 10000);
}
printf("%.4lf", ans / 10000.);
return 0;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
sure.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%lf %lf", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |