Submission #153007

#TimeUsernameProblemLanguageResultExecution timeMemory
153007georgerapeanu구경하기 (JOI13_watching)C++11
100 / 100
187 ms16060 KiB
#include <cstdio>
#include <algorithm>

using namespace std;

int n,p,q;
int a[2005];
int dp[2005][2005];

bool ok(int w){
    if(n <= p + q){
        return true;
    }

    int l1 = 0;
    int l2 = 0;

    for(int i = 1;i <= n;i++){
        while(l1 < i && a[i] - a[l1 + 1] >= w){
            l1++;
        }
        while(l1 < i && a[i] - a[l2 + 1] >= 2 * w){
            l2++;
        }
        for(int j = 0;j <= p;j++){
            dp[i][j] = dp[l2][j] + 1;
            if(j){
                dp[i][j] = min(dp[i][j],dp[l1][j - 1]);
            }          
        }
    }

    for(int i = 0;i <= p;i++){
        if(dp[n][i] <= q){
            return true;
        }
    }

    return false;
}

int main(){

    scanf("%d %d %d",&n,&p,&q);

    for(int i = 1;i <= n;i++){
        scanf("%d",&a[i]);
    }

    sort(a + 1,a + 1 + n);

    int st = 0;
    int dr = 1e9;

    while(dr - st > 1){
        int mid = st + (dr - st) / 2;
        
        if(ok(mid)) {
            dr = mid;
        }
        
        else {
            st = mid;
        }
    }

    printf("%d\n",dr);

    return 0;
}

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&p,&q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...