#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
cout<<fixed<<setprecision(4);
int n;
cin>>n;
vector<double> a,b;
for(int i=0;i<n;i++)
{
double x,y;
cin>>x>>y;
a.push_back(x);
b.push_back(y);
}
sort(rbegin(a),rend(a));
sort(rbegin(b),rend(b));
vector<double> pre0,pre1;
pre1=pre0={0};
for(int i=0;i<n;i++)
{
pre0.push_back(pre0.back()+a[i]);
pre1.push_back(pre1.back()+b[i]);
}
int j=0;
double ans=0;
n++;
for(int i=0;i<n;i++)
{
while(j<n and pre1[j]<pre0[i])
{
j++;
}
if(j!=n)
{
ans=max(ans,pre0[i]-i-j);
}
// pre[j] >= pre[i]
}
j=0;
for(int i=0;i<n;i++)
{
while(j<=n and pre0[j]<pre1[i])
{
j++;
}
if(j!=n)
{
ans=max(ans,pre1[i]-i-j);
}
// pre[j] >= pre[i]
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |