This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
#define fb(i,s,f) for(int (i)=s-1;(i)>=f;(i)--)
#define ffi(i,s,f) for(int (i)=s;(i)<=(f);(i)++)
#define fbi(i,s,f) for(int (i)=s;(i)>=(f);(i)--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;
const int maxn=1e5+10;
double a[maxn];
double b[maxn];
void solve(){
int n;
cin>>n;
ff(i,0,n){
cin>>a[i]>>b[i];
}
sort(a,a+n,greater<double>());
sort(b,b+n,greater<double>());
double res=0;
double suma=0,sumb=0;
int inda=0,indb=0;
while(true){
if(suma<sumb){
if(inda==n) break;
suma+=a[inda];
inda++;
}else{
if(indb==n) break;
sumb+=b[indb];
indb++;
}
res=max(res,min(suma,sumb)-inda-indb);
}
cout<<fixed<<showpoint<<setprecision(4)<<res<<"\n";
}
int main(){
ios;
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
sure.cpp: In function 'void solve()':
sure.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
| ^
sure.cpp:35:5: note: in expansion of macro 'ff'
35 | ff(i,0,n){
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |