이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> dl;
typedef vector<ii> vii;
typedef vector<dl> vdll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define in insert
#define bs binary_search
#define rc(s) return cout << s,0
const ll mod=1e9+7;
const int N=100005;
#define M_PI 3.14159265358979323846
#define INF INT_MAX
#define sz(x) ((int)(x.size()))
#define int ll
#define endl '\n'
#define map unordered_map
/*----------------------------*/
int dp[5005][5005],a[5005];
/*----------------------------*/
int32_t main() {
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=0;i<=n;i++)for(int j=0;j<=k;j++)dp[i][j]=INF;
dp[1][1]=a[1];
for(int j=1;j<=k;j++)
{
for(int i=1;i<=n;i++)
{
if(i==1)dp[i][j]=a[1];
else dp[i][j]=min(min(dp[i-1][j-1]+1,dp[i-1][j]+a[i]-a[i-1]),dp[i][j-1]);
//cout<<dp[i][j]<<" ";
}
//cout<<endl;
}
rc(dp[n][k]);
//THIS IS IS THE END
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |