제출 #296974

#제출 시각아이디문제언어결과실행 시간메모리
296974ahmad_salahK개의 묶음 (IZhO14_blocks)C++17
0 / 100
1 ms512 KiB
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #include <bits/stdc++.h> using namespace std; const int M = 1e5 + 1; int big = 1e9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int dp[n + 1][k + 1], a[n], greater[n]; for (int &x : a) cin >> x; stack<int> st; for (int i = 0; i < n; i++) { while (!st.empty() && a[st.top()] < a[i]) greater[st.top()] = i, st.pop(); st.push(i); } while (!st.empty()) greater[st.top()] = n, st.pop(); for (int i = 0; i < k; i++) dp[n][i] = big; for (int i = 0; i < n; i++) dp[i][k] = big; dp[n][k] = 0; for (int i = n - 1; i >= 0; i--) for (int j = k - 1; j >= 0; j--) dp[i][j] = min(dp[greater[i]][j], a[i] + dp[i + 1][j + 1]); cout << dp[0][0] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...