Submission #718668

# Submission time Handle Problem Language Result Execution time Memory
718668 2023-04-04T13:41:17 Z AndrijaM Stove (JOI18_stove) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

int n,k;
int dp[5005][5005];
int x[5005];

int f(int idx,int p)
{
    if(idx==n+1)return 0;
    if(p==0)return 2e9;
    if(dp[idx][p]!=2e9)
    {
        cout<<idx<<" "<<p<<endl;
        return dp[idx][p];
    }
    int rez=2e9;
    for(int i=idx;i<=n;i++)
    {
        if(p-1>=0)
        {
            rez=min(rez, f(i+1,p-1)+x[i]-x[idx]+1);
        }
    }
    return dp[idx][p]=rez;
}

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=2e9;
        }
    }
    cout<<f(1,k)<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -