제출 #885089

#제출 시각아이디문제언어결과실행 시간메모리
885089vjudge1K개의 묶음 (IZhO14_blocks)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n" #define ii pair<int,int> #define X first #define Y second const long long MAX = (int)1e5 + 5; const long long INF = (int)1e9; const long long MOD = (int)1e9 + 7; int n,k; int a[MAX]; int dp[2][MAX]; signed main(){ read(); cin >> n >> k; int bit = 0; for(int i = 1;i <= n;i++){ cin >> a[i]; dp[bit][i] = INF; } for(int j = 1;j <= k;j++){ bit = 1 - bit; stack<ii> st; for(int i = 1;i <= n;i++){ if(i < j)continue; int summ = dp[1 - bit][i - 1]; // if(st.size()) // cout << i << " " << st.size() << " " << a[st.top().X] << " " << a[i] << "\n"; while(!st.empty() && a[st.top().X] <= a[i]){ summ = min(summ,st.top().Y); // cout << st.top().X << "\n"; st.pop(); } //cout << summ << " " << a[i] << ' '; dp[bit][i] = summ + a[i]; if(!st.empty()){ dp[bit][i] = min(dp[bit][i],a[st.top().X] + st.top().Y); } st.push({i,summ}); //cout << dp[bit][i] << " "; } //cout << "\n"; } cout << dp[bit][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...