//
// main.cpp
//
// Created by Panagiotis Chadjicostas on
// Copyright © Panagiotis Hadjicostas. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
typedef int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#ifdef px
#define p(x) cerr<<#x<<' '<<x<<endl;
#else
#define p(x) {}
#endif
#define F first
#define S second
#define sz size
#define ls s,m,idx<<1
#define rs m+1,e,idx<<1|1
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
///////////////////////////////////////////////////////////////////////
void solve(){
ll n,k;cin>>n>>k;
vector<ll> a(n+1,ll());
for(ll i=1;i<=n;i++)cin>>a[i];
// logika fasi dp[i][x], eimai ston i kai xrisimopoio x stove
// dp [i] [x] = dp [i-1] [x-1] + 1
// dp [i] [x] = dp [i-1] [x] + a[i] - a[i-1] + 1;
ll dp [n+2][k+2];
for(ll i=0;i<n+2;i++){
for(ll j=0;j<k+2;j++){
dp[i][j]=MOD;
}
}
dp[1][1]=1;
for(ll i=2;i<=n;i++){
for(ll x=1;x<=k;x++){
dp[i][x] = dp[i-1][x-1] + 1;
dp[i][x]=min(dp[i][x],dp[i-1][x]+a[i]-a[i-1]);
}
}
cout<<dp[n][k]<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;//cin>>t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
1492 KB |
Output is correct |
12 |
Correct |
11 ms |
12116 KB |
Output is correct |
13 |
Correct |
21 ms |
23752 KB |
Output is correct |
14 |
Correct |
30 ms |
34416 KB |
Output is correct |
15 |
Correct |
31 ms |
35488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
1492 KB |
Output is correct |
12 |
Correct |
11 ms |
12116 KB |
Output is correct |
13 |
Correct |
21 ms |
23752 KB |
Output is correct |
14 |
Correct |
30 ms |
34416 KB |
Output is correct |
15 |
Correct |
31 ms |
35488 KB |
Output is correct |
16 |
Correct |
13 ms |
6288 KB |
Output is correct |
17 |
Correct |
43 ms |
41560 KB |
Output is correct |
18 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |