이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
using namespace std;
deque <pair <ll,ll> > v;
ll dp[101][100001],a[100001];
int main()
{
ll n,k,i,j;
cin>>n>>k;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=0;i<=n;i++)
for(j=0;j<=k;j++)
dp[j][i]=1e9;
dp[0][0]=0;
for(i=1;i<=k;i++)
{
v.clear();
for(j=1;j<=n;j++)
{
ll s=dp[i-1][j-1];
if (j<i)
{
dp[i][j]=1e9;
continue;
}
while(!v.empty() && v.front().fr<=a[j])
{
//cout<<v.front().first<<" delete "<<v.front().sc<<endl;
s=min(s,v.front().sc);
v.pop_front();
}
if (!v.empty() && v.front().fr+v.front().sc<=s+a[j])
dp[i][j]=v.front().fr+v.front().sc;
else
{
dp[i][j]=s+a[j];
v.push_front({a[j],s});
//cout<<v.front().first<<" add "<<v.front().sc<<endl;
}
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
cout<<dp[k][n];
return 0;
}
# | 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... |