이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
const ll NMAX = 100001;
const ll INF = (1 << 16) - 1;
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 20;
int dp[2][NMAX];
int main() {
//ifstream cin("multigraph.in");
//ofstream cout("multigraph.out");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, i, j, last = 0, maxim = 2e9, k;
cin >> n >> k;
for(i = 0; i <= k; i++)
dp[0][i] = dp[1][i] = 2e9;
for(i = 1; i <= n; i++){
int x;
cin >> x;
if(i == 1){
dp[1][1] = 1;
}else{
for(j = 1; j <= k; j++){
dp[i % 2][j] = dp[(i - 1) % 2][j] + (x - last);
dp[i % 2][j] = min(dp[(i - 1) % 2][j - 1] + 1, dp[i % 2][j]);
if(i == n)
maxim = min(maxim, dp[i % 2][j]);
}
}
last = x;
}
cout << maxim;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |