// 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];
memset(f,oo,sizeof(f));
f[0][0]=0;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=i;j++)
{
ll mx = 0;
for(ll l=i;l>=j;l--)
{
mx = max(mx,a[l]);
f[i][j] = min(f[i][j],f[l-1][j-1]+mx);
}
}
}
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.
Compilation message
blocks.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
115 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |