/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <bitset>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n,k;
LD a[100005],b[100005],sx,sy,ans=0;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
sort(a+1,a+1+n);
sort(b+1,b+1+n);
reverse(a+1,a+1+n);
reverse(b+1,b+1+n);
for(int i=1;i<=n;i++)
{
sx+=a[i];
k=0;
sy=0;
ans=max(ans,min(sx,sy)-(LD)i-(LD)k);
while(k<n)
{
k++;
sy+=b[k];
ans=max(ans,min(sx,sy)-(LD)i-(LD)k);
}
}
printf("%.4lf\n",ans);
return 0;
}
/*
2
1 2
1 3
*/
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:53:25: warning: format '%lf' expects argument of type 'double', but argument 2 has type 'long double' [-Wformat=]
printf("%.4lf\n",ans);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |