#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
vector<double> a,b,c,d;
int TS(int x,int l,int r){
if(l==r)return l;
int ml=l+(r-l)/3;
int mr=r-(r-l)/3;
double p=min(c[x]-ml-1,d[ml]-x-1);
double q=min(c[x]-mr-1,d[mr]-x-1);
if(r-l==1){
if(p>q)return l;
return r;
}
if(r-l==2){
if(p<q)return TS(x,l+1,r);
return TS(x,l,r-1);
}
if(p<q)return TS(x,ml,r);
else return TS(x,l,mr);
}
int main() {
int n;cin>>n;
a.resize(n);b.resize(n);c.resize(n);d.resize(n);
REP(i,0,n)cin>>a[i]>>b[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
double ans=0;
c[0]=a[0]-1;
REP(i,1,n)c[i]=a[i]+c[i-1]-1;
d[0]=b[0]-1;
REP(i,1,n)d[i]=b[i]+d[i-1]-1;
REP(i,0,n){
int k=TS(i,0,n-1);
ans=max(ans,min(c[i]-k-1,d[k]-i-1));
}
cout<<fixed<<setprecision(4)<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
448 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
448 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
116 ms |
4820 KB |
Output is correct |
18 |
Correct |
155 ms |
4840 KB |
Output is correct |
19 |
Correct |
110 ms |
4832 KB |
Output is correct |
20 |
Correct |
113 ms |
4824 KB |
Output is correct |
21 |
Correct |
119 ms |
5204 KB |
Output is correct |
22 |
Correct |
113 ms |
4692 KB |
Output is correct |
23 |
Correct |
114 ms |
4844 KB |
Output is correct |
24 |
Correct |
126 ms |
4712 KB |
Output is correct |
25 |
Correct |
120 ms |
4704 KB |
Output is correct |
26 |
Correct |
145 ms |
5104 KB |
Output is correct |