Submission #1247859

#TimeUsernameProblemLanguageResultExecution timeMemory
1247859vlomaczkStove (JOI18_stove)C++20
50 / 100
145 ms327680 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n, k;
	cin >> n >> k;
	vector<ll> T(n+1);
	for(int i=1; i<=n; ++i) cin >> T[i];
	ll inf = 1e15;
	vector<vector<ll>> dp(n+1, vector<ll>(k+1, inf));
	dp[0][0] = 0;
	for(int i=1; i<=n; ++i) {
		int d = T[i]-T[i-1];
		for(int x=1; x<=k; ++x) {
			dp[i][x] = min(dp[i-1][x] + d, dp[i-1][x-1]+1);
		}
	}
	cout << dp[n][k] << "\n";

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...