#include <bits/stdc++.h>
#define pb push_back
#define all(q) q.begin (), q.end ()
#define ll long long
#define f first
#define s second
using namespace std;
const ll MOD = 1e9 + 7;
const ll inf = 1e9 + 1;
const ll INF = 1e18 + 1;
const ll N = 2e6 + 1;
const int k = 15;
double a[N], b[N];
void solve (){
int n;
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i] >> b[i];
// a[i] -= 1;
// b[i] -= 1;
}
sort (a + 1, a + 1 + n);
sort (b + 1, b + 1 + n);
reverse (a + 1, a + 1 + n);
reverse (b + 1, b + 1 + n);
// cout << '\n';
// for (int i = 1; i <= n; ++i) cout << a[i] << ' ' << b[i] << '\n';
// cout << '\n';
int l = 1, r = 1, t = 0;
double q = 0, w = 0, ans = 0;
while (l != n + 1 && r != n + 1){
while (l != n + 1 && q <= w){
// cout << l << ' ';
q += a[l];
++t;
++l;
// cout << q << ' ' << w << '\n';
ans = max (ans, min (q, w) - t);
}
while (r != n + 1 && q >= w){
// cout << r << ' ';
w += b[r];
++r;
++t;
// cout << q << ' ' << w << '\n';
ans = max (ans, min (q, w) - t);
}
}
cout << fixed << setprecision (5);
cout << ans;
}
main (){
ios_base::sync_with_stdio (0);
cin.tie (0);
// freopen("guard.in", "r", stdin);
// freopen("guard.out", "w", stdout);
ll t = 1;
// cin >> t;
for (ll i = 1; i <= t; ++i){
// cout << "Case " << i << ':' << '\n';
solve ();
// cout << '\n';
}
}
Compilation message
sure.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
57 | main (){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |