이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// NHDanDz
#include <bits/stdc++.h>
#define nmax 100005
#define F first
#define S second
#define PB push_back
#define PF push_front
#define ll long long
//#define int ll
#define RyoLoveHentai "blocks"
#define pii pair<int,int>
#define reset(a) memset(a,0,sizeof(a))
using namespace std;
int n , k , a[nmax] , d[105][100005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
memset(d , 19 , sizeof(d));
d[1][0] = 0;
for(int i = 1; i <= n ; i++)
d[1][i] = max(d[1][i - 1] , a[i]);
for(int i = 2; i <= k; i++)
{
stack <pii> S;
for(int j = i; j <= n; j++)
{
int MIN = d[i - 1][j - 1];
//cout << MIN << " ";
while(S.size() && a[S.top().S] <= a[j])
{
MIN = min(MIN , S.top().F);
S.pop();
}
d[i][j] = min(d[i][S.size() ? S.top().S : 0] , MIN + a[j]);
//cout << (S.size() ? S.top().S : 0) << " ";
S.push({MIN , i});
}
//cout << endl;
}
cout << d[k][n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |