#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
bool srt(float a, float b) {
return a > b;
}
int main() {
int n, f = 0, s = 0;
float fsum = 0, ssum = 0, res = 0;
cin >> n;
vector<float> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a.begin(), a.end(), srt);
sort(b.begin(), b.end(), srt);
fsum = a[0];
f++;
while(f < n && s < n) {
if(fsum > ssum) {
while(fsum > ssum && s < n) {
ssum+=b[s];
s++;
res = max(res, min(fsum, ssum)-f-s);
}
} else {
while(ssum > fsum && f < n) {
fsum+=a[s];
f++;
res = max(res, min(fsum, ssum)-f-s);
}
}
}
cout << fixed << setprecision(4) << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |