#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "teams.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const ll nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,j,l,r,mid,rs;
double a[nmax],b[nmax],p[nmax],s[nmax],ans;
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n;
for(i=1;i<=n;i++)cin>>a[i]>>b[i];
sort(a+1,a+n+1);
sort(b+1,b+n+1);
reverse(a+1,a+n+1);
reverse(b+1,b+n+1);
for(i=1;i<=n;i++)p[i]=p[i-1]+a[i];
for(i=1;i<=n;i++)s[i]=s[i-1]+b[i];
for(i=1;i<=n;i++)
{
l=1,r=n;
while(l<=r)
{
mid=(l+r)/2;
if(s[mid]>=p[i])rs=mid,r=mid-1;
else l=mid+1;
}
if(p[i]<=s[n])ans=max(ans,p[i]-i-rs);
l=1,r=n;
while(l<=r)
{
mid=(l+r)/2;
if(p[mid]>=s[i])rs=mid,r=mid-1;
else l=mid+1;
}
if(s[i]<=p[n])ans=max(ans,s[i]-i-rs);
}
cout<<fixed<<setprecision(4)<<ans<<endl;
return 0;
}
Compilation message
sure.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
sure.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
97 ms |
4904 KB |
Output is correct |
18 |
Correct |
100 ms |
4864 KB |
Output is correct |
19 |
Correct |
100 ms |
4856 KB |
Output is correct |
20 |
Correct |
143 ms |
4860 KB |
Output is correct |
21 |
Correct |
104 ms |
5140 KB |
Output is correct |
22 |
Correct |
96 ms |
4856 KB |
Output is correct |
23 |
Correct |
96 ms |
4856 KB |
Output is correct |
24 |
Correct |
99 ms |
4808 KB |
Output is correct |
25 |
Correct |
94 ms |
4856 KB |
Output is correct |
26 |
Correct |
104 ms |
5228 KB |
Output is correct |