#include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main() {
int n;
cin >> n;
vector<ld> v1(n), v2(n);
for(int i = 0; i<n; i++) {
ld a, b;
cin >> a >> b;
v1[i] = a;
v2[i] = b;
}
sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end());
reverse(v1.begin(), v1.end()); reverse(v2.begin(), v2.end());
ld ptr1 = 0, ptr2 = 0;
ld val1 = 0, val2 = 0, rem = 0;
ld ans = 0;
/*
for(int i : v1) cout << i << " ";
cout << "\n";
for(int i : v2) cout << i << " ";
cout << "\n";
*/
while(ptr1 <= n && ptr2 <= n) {
if(val1 < val2) {
val1 += v1[ptr1];
ptr1++;
rem += 1;
}
else{
val2+= v2[ptr2];
ptr2++;
rem += 1;
}
ans = max(ans, min(val1, val2) - rem);
}
printf("%.4LF", ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |