#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
const int lim = 1e5 + 5;
int n;
ll a[lim], b[lim];
namespace sub1{
vector<int>current(1, -1);
ll ans = 0;
void play(int p){
if(p > n){
int cnt = 0;
ll A = 0, B = 0;
for(int i = 1; i <= n; i++){
if(current[i] > 0){
cnt++;
if(current[i] == 1){
A += a[i];
}
else if(current[i] == 2){
B += b[i];
}
else{
A += a[i];
B += b[i];
cnt++;
}
}
}
maximize(ans, min(A, B) - cnt * 10000);
return;
}
for(int i = 0; i < 4; current.pop_back(), i++){
current.emplace_back(i);
play(p + 1);
}
}
void solve(){
play(1);
cout << setprecision(4) << fixed << double(ans) / 1e4;
}
}
namespace sub23{
void solve(){
sort(a + 1, a + n + 1, greater<ll>());
sort(b + 1, b + n + 1, greater<ll>());
a[0] = b[0] = 0;
for(int i = 1; i <= n; i++){
a[i] += a[i - 1];
b[i] += b[i - 1];
}
ll low = 1, high = 1e13, ans = 0;
while(low <= high){
ll mid = (low + high) >> 1LL;
bool can = false;
for(int i = 1; i <= (n << 1); i++){
if(min(a[n], b[n]) < mid + i * 10000){
break;
}
if((lower_bound(a + 1, a + n + 1, mid + i * 10000) - a) + (lower_bound(b + 1, b + n + 1, mid + i * 10000) - b) <= i){
can = true;
break;
}
}
if(can){
low = (ans = mid) + 1;
}
else{
high = mid - 1;
}
}
cout << setprecision(4) << fixed << double(ans) / 1e4;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
for(int i = 1; i <= n; i++){
double A, B;
cin >> A >> B;
a[i] = ll(A * 1e4);
b[i] = ll(B * 1e4);
}
if(n <= 10){
sub1::solve();
}
else{
sub23::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
sure.cpp: In function 'int main()':
sure.cpp:84:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |