Submission #971507

#TimeUsernameProblemLanguageResultExecution timeMemory
971507njoopK blocks (IZhO14_blocks)C++14
0 / 100
58 ms173140 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, arr[100010]; pair<int, int> dp[100010][110]; signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; for(int i=1; i<=n; i++) { cin >> arr[i]; } for(int i=0; i<100010; i++) { for(int j=0; j<110; j++) { dp[i][j] = {1e18, 1e18}; } } dp[1][1] = {arr[1], arr[1]}; for(int i=1; i<n; i++) { for(int j=1; j<=k; j++) { if(j > i) continue; if(dp[i+1][j+1].first > dp[i][j].first + arr[i+1]) { dp[i+1][j+1].first = dp[i][j].first + arr[i+1]; dp[i+1][j+1].second = arr[i+1]; } if(dp[i+1][j].first > dp[i][j].first) { dp[i+1][j].first = dp[i][j].first; if(dp[i][j].second < arr[i+1]) { dp[i+1][j].first += arr[i+1] - dp[i][j].second; dp[i+1][j].second = arr[i+1]; } } } } cout << dp[n][k].first; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...