#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n; cin>>n;
vector<double> a(n),b(n);
for (int i=0; i<n; i++) cin>>a[i]>>b[i];
sort(a.begin(),a.end(),greater<double>());
sort(b.begin(),b.end(),greater<double>());
//now take prefix sums
for (int i=1; i<n; i++){
a[i]=a[i-1]+a[i];
}
for (int i=1; i<n; i++){
b[i]=b[i-1]+b[i];
}
double ans=0;
int r=0;
for (int i=0; i<n; i++){
while (r<n and b[r]<a[i]) r++;
if (r>=n) break;
ans=max(ans, a[i]-(i+1+r+1));
}
r=0;
for (int i=0; i<n; i++){
while (r<n and a[r]<b[i]) r++;
if (r>=n) break;
ans=max(ans, b[i]-(i+1+r+1));
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |