Submission #171892

#TimeUsernameProblemLanguageResultExecution timeMemory
171892NightmarK blocks (IZhO14_blocks)C++17
53 / 100
1050 ms380 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define read freopen("input.txt", "r", stdin) #define write freopen("output.txt", "w", stdout) #define files read; write using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = (int)1e3 + 228; const int N = (int)1e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; int a[N]; int dp[N][111]; int main() { SWS; //files; int n, k; cin >> n >> k; for (int i = 0; i <= k; i++) for (int j = 0; j <= n; j++) dp[i][j] = INF; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = 0; for (int block = 1; block <= k; block++) for (int i = block; i <= n; i++) { int mx = a[i]; for (int j = i - 1; j >= block - 1; j--) { dp[block][i] = min(dp[block][i], dp[block - 1][j] + mx); mx = max(mx, a[j]); } } cout << dp[k][n]; 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...