Submission #77290

# Submission time Handle Problem Language Result Execution time Memory
77290 2018-09-24T19:28:59 Z MohamedAhmed0 Watching (JOI13_watching) C++14
0 / 100
227 ms 263168 KB
#include <bits/stdc++.h>

using namespace std;

int dp[2001][100001] , arr[2001];

int n , p , q ;

int check(int idx , int r , int re , int x , int covered)
{
    if(idx == n+1)
       return 1 ;
    int &ret = dp[idx][r] ;
    if(ret != -1)
        return ret ;
    ret = 0 ;
    if(arr[idx] <= covered)
        ret = check(idx+1 , r , re , x , covered);
    else
    {
        if(r == 0 && re == 0)
            return 0 ;
        if(r != 0)
          ret = check(idx+1 , r-1 , re , x , arr[idx] + x-1);
        if(re != 0)
          ret = max(ret , check(idx+1 , r , re-1 , x , arr[idx] + x*2-1));
    }
    return ret ;
}

int main()
{
    cin>>n>>p>>q ;
    if(p+q >= n)
        return cout<<1 , 0 ;
    int MAX = 0 ;
    for(int i = 1 ; i <= n ; ++i)
    {
         cin>>arr[i] ;
         MAX = max(MAX , arr[i]);
    }
    //sort(arr , arr + n + 1);
    sort(arr , arr + n + 1);
    int l = 1 , r = MAX , ans = 1e9;
    while(l <= r)
    {
        memset(dp , -1 , sizeof(dp));
        int mid = (l + r) / 2 ;
        if(check(1 , p , q , mid , 0))
            r = mid-1 , ans = min(ans , mid);
        else
            l = mid+1;
    }
    return cout<<ans<<"\n" , 0 ;
}
# Verdict Execution time Memory Grader output
1 Runtime error 227 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -