Submission #1327983

#TimeUsernameProblemLanguageResultExecution timeMemory
1327983darkdevilvaqifWatching (JOI13_watching)C++20
100 / 100
160 ms16272 KiB
/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define rsz resize
#define fi first
#define se second
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define endl "\n"
#define newline cout << endl;
using namespace std;
 
// constants

// functions

// structs

// globals

// notes
/*
My favorite anime is One Piece(obviously)
My oshi(Yes, I have an oshi, deal with it) is Kamil_Tsubaki

 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/
 
void solve()
{
    int n, S, B;
    cin >> n >> S >> B;
    vector <int> es(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> es[i];
    }
    
    sort(all(es));
    S = min(n, S);
    B = min(n, B);
    auto check = [&](int x)
    {
        vector <int> nxt(n + 2), nxt2(n + 2);
        nxt[n + 1] = nxt2[n + 1] = n + 1;
        for (int i = 1; i <= n; i++)
        {
            nxt[i] = lower_bound(all(es), es[i] + x) - es.begin();
            nxt2[i] = lower_bound(all(es), es[i] + 2 * x) - es.begin();
        }
        
        vector <vector <int> > dp(S + 1, vector <int>(B + 1, 1));
        for (int i = 0; i <= S; i++)
        {
            for (int j = 0; j <= B; j++)
            {
                if (dp[i][j] > n)
                {
                    return true;
                }
                
                if (i < S)
                {
                    dp[i + 1][j] = max(dp[i + 1][j], nxt[dp[i][j]]);
                }
                if (j < B)
                {
                    dp[i][j + 1] = max(dp[i][j + 1], nxt2[dp[i][j]]);
                }
            }
        }
        return dp[S][B] > n;
    };
    
    int L = 1, R = 1e9;
    while (L <= R)
    {
        int mid = L + R >> 1;
        
        if (check(mid))
        {
            R = mid - 1;
        }
        else
        {
            L = mid + 1;
        }
    }
    
    cout << L;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...