이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int N = 1e5+10;
const int K = 1e4;
ld a[N], b[N], p[N];
ll n;
ld genx() {
ld x=0, sm=0;
for (ll i=1; i<=n; ++i) {
sm+=a[i];
ll lf=0, rf=n, res=0;
while (lf <= rf) {
ll m=(lf+rf)/2;
if (sm-m >= p[m]-i) lf=m+1, res=m;
else rf=m-1;
}
ld val=max(min(sm-res, p[res]-i), min(sm-(res+1), p[res+1]-i));
x=max(x, val);
} return x;
}
void solve() {
cin>>n;
for (int i=1; i<=n; ++i) {
cin>>a[i]>>b[i]; --a[i], --b[i];
} sort(a+1, a+n+1, greater<ld>()), sort(b+1, b+n+1, greater<ld>());
for (int i=1; i<=n+1; ++i) p[i]=p[i-1]+b[i];
ld ans=genx();
swap(a, b);
p[0]=0;
for (int i=1; i<=n+1; ++i) p[i]=p[i-1]+b[i];
ans=max(ans, genx());
printf("%.4lf", (double)ans);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
while (t--) 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... |