제출 #1304470

#제출 시각아이디문제언어결과실행 시간메모리
1304470disfyyStove (JOI18_stove)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll N = 5e5 + 5; const ll NN = 5e3 + 5; const ll INF = 2e18 + 5; const ll MOD = 1e9 + 7; const ll P = 53; const double eps = 1e-9; ll dp[NN][NN], a[N]; void solve() { ll n, k; cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; } a[0] = a[1] - 1; for(ll i = 1; i <= n; i++) { ll x = min(i, k); for(int j = 1; j <= x; j++) { dp[i][j] = dp[i - 1][j] + (a[i] - a[i - 1]); } if(a[i - 1] + 1 != a[i]) { for(int j = 2; j <= x; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1); } } } cout << dp[n][k] << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int test = 1; // cin >> test; for(int i = 1; i <= test; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...