제출 #885091

#제출 시각아이디문제언어결과실행 시간메모리
885091vjudge1K개의 묶음 (IZhO14_blocks)C++17
100 / 100
106 ms1924 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(j > i)continue; int summ = dp[1 - bit][i - 1]; //cout << summ << " :\n"; while(!st.empty() && a[st.top().X] <= a[i]){ //cout << st.top().Y << " " << st.top().X << "A\n"; summ = min(summ,st.top().Y); st.pop(); } //cout << summ << "\n"; if(st.empty() || a[st.top().X] + st.top().Y > a[i] + summ){ st.push({i,summ}); } if(i >= j){ //cout << st.top().X << " " << st.top().Y << '\n'; dp[bit][i] = a[st.top().X] + st.top().Y; } //cout << dp[bit][i] << " "; } for(int i = 0;i <= n;i++){ dp[1 - bit][i] = INF; } //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...