제출 #854798

#제출 시각아이디문제언어결과실행 시간메모리
854798NeroZeinK개의 묶음 (IZhO14_blocks)C++17
0 / 100
0 ms600 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n); vector<long long> dp(n); for (int i = 0; i < n; ++i) { cin >> a[i]; dp[i] = max(dp[i - 1], (long long) a[i]); } for (int j = 1; j < k; ++j) { stack<pair<int, long long>> stk; for (int i = j; i < n; ++i) { while (!stk.empty() && stk.top().second <= a[i - 1]) { stk.pop(); } if (stk.empty() || (stk.top().first + stk.top().second > a[i - 1] + dp[i - 1])) { stk.push({a[i - 1], dp[i - 1]}); } dp[i] = stk.top().first + stk.top().second; } } cout << dp[n - 1] << '\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...