이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define s second
#define f first
#define left (h<<1),l,(l+r)>>1
#define right ((h<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int N = 100005;
double a[N],b[N],A[N],B[N];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>a[i]>>b[i];
sort(a+1,a+n+1);
sort(b+1,b+n+1);
for (int i = n; i >= 1; i--){
A[i] = A[i + 1] + a[i];
B[i] = B[i + 1] + b[i];
}
double ans = 0.0;
for (int i = n; i >= 1; i--){
int l = 1,r = n,res=0;
while(l <= r){
int mid = (l+r)>>1;
if (B[mid] >= A[i]) {
res = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
int tot = 2*n - i + 2 - res;
if (res && A[i] - tot > ans)
ans = A[i] - tot;
}
for (int i = n; i >= 1; i--){
int l = 1,r = n,res=0;
while(l <= r){
int mid = (l+r)>>1;
if (A[mid] >= B[i]) {
res = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
int tot = 2*n - i + 2 - res;
if (res && B[i] - tot > ans)
ans = B[i] - tot;
}
printf("%.4f",ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |