이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
double arr1[n];
double arr2[n];
for(int i=0; i<n; i++){
cin >> arr1[i] >> arr2[i];
}
sort(arr1, arr1+n, greater<double>());
sort(arr2, arr2+n, greater<double>());
double pref1[n];
double pref2[n];
pref1[0]=arr1[0]-1;
pref2[0]=arr2[0]-1;
for(int i=1; i<n; i++){
pref1[i]=pref1[i-1]+arr1[i]-1;
pref2[i]=pref2[i-1]+arr2[i]-1;
}
double maxx = 0;
for(int i=0; i<n; i++){
if(pref1[i]<=0){
break;
}
else{
// find first position such that pref1[i]-b<pref2[b]-i
int pos1 = 0;
int pos2 = n-1;
while(pos1<pos2){
int mid = (pos1+pos2)/2;
if(pref1[i]-mid<=pref2[mid]-i){
pos2 = mid;
}
else{
pos1=mid+1;
}
}
maxx = max(maxx, min(pref1[i]-pos1, pref2[pos1]-i)-1);
if(pos1>0){
maxx = max(maxx, min(pref1[i]-(pos1-1), pref2[pos1-1]-i)-1);
}
if(pos1<n-1){
maxx = max(maxx, min(pref1[i]-(pos1+1), pref2[pos1+1]-i)-1);
}
}
}
printf("%.4lf",(double) maxx);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |