이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Solved by VituraL
#include <bits/stdc++.h>
#define pi pair<ll,ll>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pb push_back
#define reset(a) memset(a,0,sizeof(a))
#define BIT_ON(mask, i) (mask | (1 << (i)))
#define BIT_OFF(mask, i) (mask ^ (1 << (i)))
#define C_BITS(i) __builtin_popcount(i)
#define GET_BIT(mask, i) ((mask >> i) & 1)
#define BIT_CHECK(x,i) (x & i)
using namespace std;
///// khai bao bien cac thu /////
const int mod = 1e9+7;
const int maxn = 1e6+7;
const int oo = 0x3f3f3f3f;
ll n,k,a[maxn],f[maxn][105];
/*
f[i][j] la trong so nho nhat de chia j so dau thanh i nhom
*/
void solve()
{
cin>>n>>k;
for(ll i=1;i<=n;i++) cin>>a[i];
for(ll i=1;i<=n;i++) f[i][1]=max(f[i-1][1],a[i]);
for(ll i=2;i<=k;i++)
{
f[0][i]=oo;
stack<pi> st;
for(ll j=i;j<=n;j++)
{
ll maxx = f[j-1][i-1];
while(!st.empty() && a[st.top().se] <= a[j])
{
maxx = min(maxx, st.top().fi);
st.pop();
}
if(st.empty())
{
f[j][i]=min(f[0][i],maxx+a[j]);
}
else f[j][i] = min(f[st.top().se][i],maxx+a[j]);
st.push({maxx,j});
}
}
cout<<f[n][k];
}
///// main /////
main()
{
//freopen("che.inp","r",stdin);
//freopen("che.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
cout << endl;
return 0;
}
// end.
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main()
| ^~~~
# | 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... |