이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = 1e18;
const ld eps = 1e-13;
const ll mod = 1e9+7;
const int i_inf = 1e9;
const int mxn = 1e5;
mt19937 _rand(time(NULL));
clock_t timer = clock();
void solve(){
int n;
cin >> n;
ld l[n], r[n];
fr(i, 0, n){
cin >> l[i] >> r[i];
}
sort(l, l+n);
reverse(l, l+n);
sort(r, r+n);
reverse(r, r+n);
ld ans = 0;
ld sa = 0;
ld sb = 0;
int a = 0;
int b = 0;
fr(i, 1, 2*n+1){
if(a == n) sb += r[b++];
else if(b == n) sa += l[a++];
else{
if(sa < sb){
sa += l[a++];
}
else{
sb += r[b++];
}
}
ans = max(ans, min(sa, sb) - i);
}
cout<<fixed<<setprecision(4)<<ans<<endl;
}
int main(){
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |