Submission #1052632

# Submission time Handle Problem Language Result Execution time Memory
1052632 2024-08-10T18:04:01 Z VMaksimoski008 Sure Bet (CEOI17_sure) C++17
100 / 100
76 ms 4432 KB
#include <bits/stdc++.h>
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

signed main() {
    int n; cin >> n;

    vector<double> a(n), b(n), pref(n);
    for(int i=0; i<n; i++) cin >> a[i] >> b[i];
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    pref[0] = b[0];
    for(int i=1; i<n; i++) pref[i] = pref[i-1] + b[i];

    double ans = 0;

    double sum1 = 0;
    //sum1, i fixed
    //(sum1 - i - 2) - j
    //(sum2 - j) - (i - 2)
    double l=0, r=1e9;
    while(r - l > 1e-6) {
        double mid = (l + r) / 2;
        bool ok = 0;

        double sum1 = 0;
        for(int i=0; i<n&&!ok; i++) {
            sum1 += a[i];
            if(sum1 - i - 2 < mid) continue;
            double tmp = (sum1 - i - 2) - mid;
            int mx = tmp;
            mx = min(mx, n-1);
            if(pref[mx] - mx - i - 2 >= mid && sum1 - i - 2 - mx >= mid) ok = 1;
        }

        if(ok) ans = l = mid;
        else r = mid;
    }

    cout << setprecision(4) << fixed << ans << '\n';
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:26:12: warning: unused variable 'sum1' [-Wunused-variable]
   26 |     double sum1 = 0;
      |            ^~~~
# Verdict Execution time Memory 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 444 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 67 ms 3672 KB Output is correct
18 Correct 70 ms 4148 KB Output is correct
19 Correct 68 ms 3916 KB Output is correct
20 Correct 68 ms 3928 KB Output is correct
21 Correct 75 ms 4432 KB Output is correct
22 Correct 67 ms 3932 KB Output is correct
23 Correct 76 ms 4048 KB Output is correct
24 Correct 71 ms 3916 KB Output is correct
25 Correct 72 ms 3932 KB Output is correct
26 Correct 75 ms 4300 KB Output is correct