제출 #1355202

#제출 시각아이디문제언어결과실행 시간메모리
1355202nini_gvenetadze구경하기 (JOI13_watching)C++20
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
using namespace std;

long long  n, p, q;
vector<int> a;
bool check(int x)
{
    int l1, l2;
    vector<vector<int>> dp(n+1, vector<int>(p+1, 1e9));
    vector<int>  L1(n+1), L2(n+1);
    for (int i=0; i<=p; i++)
    dp[0][i]=0;
    for(int i=1; i<=n; i++)
    {
          l1=i, l2=i;
         while(l1>0 && a[i]-a[l1]<x) l1--;
         while(l2>0 && a[i]-a[l2]<2*x) l2--;
         
        L1[i]=l1;


        L2[i]=l2;  
        
    }
    for(int i=1; i<=n; i++)
    {
        l1 = L1[i], l2 = L2[i];
    for(int j=0; j<=p; j++)
    {
        //patara photo
        if(j>0){
        dp[i][j]=min(dp[i][j], dp[l1][j-1]);}
       //didi photo
       dp[i][j]=min(dp[i][j], dp[l2][j]+1);
    }
    }

         
    if(dp[n][p]<=q) return true;
            
    return false;
   

}
int main() {
    // int  n, p, q;
     cin>>n>>p>>q;
     a.resize(n+1);
     for(int i=1; i<=n; i++) 
     {
        cin>>a[i];
     }
     sort(a.begin()+1, a.end());
     int l=0, r=100;
     int ans=r;
     while(l<=r)
     {
        int mid=(l+r)/2;// cout<<l<<" "<<r<<endl;
        if(check(mid))
        {
           
             ans=mid;
             r=mid-1;
        }
        else
        l=mid+1;
     }
    cout<<ans<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...