Submission #154475

#TimeUsernameProblemLanguageResultExecution timeMemory
154475srvltK blocks (IZhO14_blocks)C++14
53 / 100
4 ms508 KiB
//#pragma GCC optimize("Ofast") //#pragma GCC target("sse2,avx") #include <bits/stdc++.h> #define ll long long #define db long double #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define fi first #define se second #define mp make_pair #define endl "\n" #define int long long using namespace std; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 103, K = 103, inf = 1e18; int n, k, a[N], dp[K][N]; void solve(int tc) { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i < K; i++) { for (int j = 0; j < N; j++) { dp[i][j] = inf; } } dp[0][0] = 0; for (int i = 1; i <= k; i++) { for (int j = i; j <= n; j++) { int mx = 0; for (int l = j; l >= 1; l--) { mx = max(mx, a[l]); dp[i][j] = min(dp[i][j], dp[i - 1][l - 1] + mx); } } } cout << dp[k][n]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int i = 0; i < tc; i++) { solve(i); // cleanup(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...