#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
/**
* CEOI 2017 - Sure Bet
* Vaqt murakkabligi: O(N log N) - saralash tufayli
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<double> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
// Eng katta koeffitsientlarni olish uchun saralaymiz
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
double max_profit = 0;
double sum_a = 0, sum_b = 0;
int j = 0;
// Ikki ko'rsatkich (Two Pointers) uslubi
for (int i = 0; i <= n; i++) {
// i - 1-natijaga tikilgan tikishlar soni
if (i > 0) sum_a += a[i-1];
// Agar sum_b hali ham sum_a dan kichik bo'lsa, sum_b ni oshiramiz
while (j < n && (sum_b < sum_a || j == 0)) {
sum_b += b[j];
j++;
max_profit = max(max_profit, min(sum_a, sum_b) - (i + j));
}
// Har bir qadamda maksimal foydani tekshiramiz
max_profit = max(max_profit, min(sum_a, sum_b) - (i + j));
}
cout << fixed << setprecision(4) << max_profit << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |