#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,st,md,ed;
double a,b,ans=0;
vector<double> v1,v2;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&a,&b);
v1.pb(-a),v2.pb(-b);
}
v1.pb(-1e9),v2.pb(-1e9);
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
for(int i=1;i<=n;i++)v1[i]=-v1[i],v2[i]=-v2[i];
for(int i=2;i<=n;i++)v1[i]=v1[i-1]+v1[i],v2[i]=v2[i-1]+v2[i];
v1[0]=0,v2[0]=0;
/*for(int i=0;i<=n;i++)
{
printf("%lf %lf\n",v1[i],v2[i]);
}*/
for(int i=1;i<=2*n;i++)
{
st=0,ed=i;
while(ed>=st)
{
md=(st+ed)/2;
if(md>n)
{
ed=md-1;
continue;
}
if(i-md>n)
{
st=md+1;
continue;
}
ans=max(ans,min(v1[md],v2[i-md])-i);
if(v1[md]<=v2[i-md])
{
st=md+1;
}else
{
ed=md-1;
}
}
//printf("i=%d\n",i);
//printf("%d %d %d\n",st,md,ed);
st-=1;
if(st>=0&&st<=n&&i-st>=0&&i-st<=n)
{
ans=max(ans,min(v1[st],v2[i-st])-i);
}
st+=1;
if(st>=0&&st<=n&&i-st>=0&&i-st<=n)
{
ans=max(ans,min(v1[st],v2[i-st])-i);
}
st-=1;
if(st>=0&&st<=n&&i-st>=0&&i-st<=n)
{
ans=max(ans,min(v1[st],v2[i-st])-i);
}
}
printf("%.4lf\n",ans);
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
sure.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%lf%lf",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
69 ms |
3356 KB |
Output is correct |
18 |
Correct |
67 ms |
3396 KB |
Output is correct |
19 |
Correct |
67 ms |
3380 KB |
Output is correct |
20 |
Correct |
69 ms |
3420 KB |
Output is correct |
21 |
Correct |
71 ms |
3812 KB |
Output is correct |
22 |
Correct |
70 ms |
3328 KB |
Output is correct |
23 |
Correct |
68 ms |
3388 KB |
Output is correct |
24 |
Correct |
78 ms |
3420 KB |
Output is correct |
25 |
Correct |
72 ms |
3372 KB |
Output is correct |
26 |
Correct |
71 ms |
3756 KB |
Output is correct |