Submission #1125301

#TimeUsernameProblemLanguageResultExecution timeMemory
1125301TsaganaK blocks (IZhO14_blocks)C++20
0 / 100
1 ms328 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define int long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; int n, k, mx; int a[100001]; int dp[100001][101]; void solve () { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); dp[i][1] = mx; } for (int i = 2; i <= k; i++) { stack<pair<int, int>> s; for (int j = 1; j <= n; j++) { dp[j][i] = 1e9; if (j < i) continue ; int mn = dp[j-1][i-1]; while (!s.empty() && a[s.top().S] <= a[n]) {mn = min(mn, s.top().F); s.pop();} if (!s.empty()) dp[j][i] = dp[s.top().S][i]; dp[j][i] = min(dp[j][i], mn + a[j]); s.push({mn, j}); } } cout << dp[n][k]; } signed main() {IOS solve(); 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...