Submission #341536

# Submission time Handle Problem Language Result Execution time Memory
341536 2020-12-29T23:29:50 Z iliccmarko Watching (JOI13_watching) C++14
100 / 100
428 ms 31980 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
ll n, p, q;
const int N = 2005;
vector<ll> a;
ll dp[N][N];



int main()
{
    ios
    cin>>n>>p>>q;
    a.pb(0);
    for(int i = 1;i<=n;i++)
    {
        ll x;
        cin>>x;
        a.pb(x);
    }
    sort(all(a));
    if(p+q>=n)
    {
        cout<<1;
        return 0;
    }

    ll ans = 1e9;
    ll l = 1;
    ll r = 1e9;
    while(l<=r)
    {
        ll mid = (r+l)/2;
        //mid = 4;
        for(int i = 0;i<=n;i++) for(int j = 0;j<=n;j++) dp[i][j] = INF;
        for(int i = 0;i<=n;i++) dp[0][i] = 0;
        for(int i = 1;i<=n;i++)
        {
            int w = a[i] - mid;
            int ind = upper_bound(all(a), w) - a.begin();
            if(ind)
            {
                ind--;
                for(int j = 0;j<=n;j++)
            {
                dp[i][j] = dp[ind][j] + 1;
            }
            }
            else
            {
                for(int j = 0;j<=n;j++)
                {
                    dp[i][j] = 1;
                    if(j) dp[i][j] = 0;
                }
            }
            ind = upper_bound(all(a), a[i] - 2*mid) - a.begin();
            if(ind)
            {
                ind--;
                for(int j = 1;j<=n;j++)
                {
                    dp[i][j] = min(dp[i][j], dp[ind][j-1]);
                }
            }
            else
            {
                for(int j = 1;j<=n;j++) dp[i][j] = 0;
            }
        }
        bool moze = false;
        for(int i = 0;i<=n;i++)
        {
            if(i<=q&&dp[n][i]<=p) moze = true;
        }
        /*for(int i = 1;i<=n;i++)
        {
            for(int j  = 0;j<=n;j++)
                cout<<dp[i][j]<<" ";
            cout<<endl;
        }*/
        if(moze)
        {
            ans = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
        //break;
    }

    cout<<ans;





    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 2 ms 876 KB Output is correct
12 Correct 2 ms 888 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 2 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 31872 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 404 ms 31980 KB Output is correct
8 Correct 407 ms 31980 KB Output is correct
9 Correct 402 ms 31852 KB Output is correct
10 Correct 410 ms 31852 KB Output is correct
11 Correct 409 ms 31980 KB Output is correct
12 Correct 410 ms 31852 KB Output is correct
13 Correct 428 ms 31852 KB Output is correct
14 Correct 415 ms 31980 KB Output is correct
15 Correct 423 ms 31852 KB Output is correct