Submission #1144725

#TimeUsernameProblemLanguageResultExecution timeMemory
1144725why1Stove (JOI18_stove)C++20
20 / 100
1094 ms23876 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int,int> #define sz size() #define all(v) v.begin(),v.end() #define fi first #define se second const int N = 2e5; const int mod = 1e9+7; const ll INF = 1e18; const int di[] = {1, -1, 0, 0}; const int dj[] = {0, 0, 1, -1}; void solve() { int n,k; cin>>n>>k; ll a[n+1]; for(int i = 1; i <= n; i++){ cin>>a[i]; } ll dp[n+1][k+1]; for(int i = 0; i <= n; i++){ for(int j = 0; j <= k; j++){ dp[i][j]=INF; } } dp[0][0]=0; for(int i = 1; i <= n; i++){ for(int K = 1; K <= min(i,k); K++){ for(int j = 1; j <= i; j++){ dp[i][K]=min(dp[i][K],dp[j-1][K-1]+a[i]-a[j]+1); } } } ll ans=INF; for(int i = 1; i <= k; i++){ ans=min(ans,dp[n][i]); } cout<<ans<<"\n"; } int main() { //freopen("cowrun.in","r",stdin); //freopen("cowrun.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...