Submission #77291

# Submission time Handle Problem Language Result Execution time Memory
77291 2018-09-24T19:36:11 Z MohamedAhmed0 Watching (JOI13_watching) C++14
0 / 100
78 ms 16412 KB
#include <bits/stdc++.h>

using namespace std;

int dp[2001][2001] , 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 ;
    if(r + re >= n - idx + (arr[idx] > covered))
        return ret = 1 ;
    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 Correct 43 ms 15992 KB Output is correct
2 Correct 2 ms 15992 KB Output is correct
3 Correct 45 ms 16036 KB Output is correct
4 Correct 2 ms 16036 KB Output is correct
5 Correct 3 ms 16036 KB Output is correct
6 Correct 2 ms 16036 KB Output is correct
7 Incorrect 42 ms 16140 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 16404 KB Output is correct
2 Correct 3 ms 16404 KB Output is correct
3 Correct 2 ms 16404 KB Output is correct
4 Correct 2 ms 16404 KB Output is correct
5 Correct 2 ms 16404 KB Output is correct
6 Correct 3 ms 16404 KB Output is correct
7 Incorrect 78 ms 16412 KB Output isn't correct
8 Halted 0 ms 0 KB -