Submission #540399

#TimeUsernameProblemLanguageResultExecution timeMemory
540399krit3379Watching (JOI13_watching)C++14
100 / 100
207 ms31696 KiB
#include<bits/stdc++.h> using namespace std; #define N 2005 long long a[N],dp[N][N],l,r,mid,ans; int main(){ int n,i,j,p,q,prep,preq; scanf("%d %d %d",&n,&p,&q); for(i=1;i<=n;i++)scanf("%lld",&a[i]); sort(a+1,a+n+1); if(p+q>=n){printf("1");return 0;} l=1,r=1e9; while(l<=r){ mid=(l+r)/2; for(i=n;i>0;i--){ prep=lower_bound(a+1,a+n+1,a[i]+mid)-a; preq=lower_bound(a+1,a+n+1,a[i]+2*mid)-a; for(j=0;j<=p;j++){ dp[i][j]=1e18; if(j>0)dp[i][j]=min(dp[i][j],dp[prep][j-1]); dp[i][j]=min(dp[i][j],dp[preq][j]+1); } } if(dp[1][p]<=q)ans=mid,r=mid-1; else l=mid+1; } printf("%lld",ans); return 0; }

Compilation message (stderr)

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