This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define MASK(i) (1LL << (i))
#define bit(mask, i) (((mask) >> (i)) & 1LL)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define Size(x) ((int)(x).size())
const int N = 1e5 + 55;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll INF = 1e9 + 7;
const int base = 137;
template<class T1, class T2>
bool Min(T1 &a, T2 b)
{
if(a > b){a=b; return true;}
return false;
}
template<class T1, class T2>
bool Max(T1 &a, T2 b)
{
if(a < b){a = b; return true;}
return false;
}
template<class T>
void Add(T &a, int b)
{
a += b;
if(a >= mod) a-=mod;
}
template<class T>
void Sub(T &a, int b)
{
a -= b;
if(a < 0) a += mod;
}
/** ---- end of template ---- **/
int dp[N][105], n, k, a[N], l[N];
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 0; i <= k; i++)
{
for(int j = 0; j <= n; j++)
{
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(int i = 1; i <= k; i++)
{
for(int j = 1; j <= n; j++)
{
int mx = 0;
for(int p = j; p >= 1; p--)
{
mx = max(mx, a[p]);
dp[i][j] = min(dp[i][j], dp[i-1][p-1] + mx);
}
}
}
cout << dp[k][n] << '\n';
}
const bool multitest = 0;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int test=1;
if(multitest) cin >> test;
while(test--)
{
solve();
}
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... |