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 <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
const ll INF = 1e18;
const ll N =(100+5); // TODO : change value as per problem
const ll K = 105;
const ll MOD = 1e9+7;
ll dp[N][K];
ll a[N];
void solve(){
ll n;
cin >> n;
ll k;
cin >> k;
for(int i =1;i<=n;i++) cin >> a[i];
ll ma= 0;
for(int i =1;i<=n;i++){
ma = max(ma,a[i]);
dp[i][1] = ma;
}
for(int i =1;i<=n;i++){
for(int j =2;j<=k;j++){
dp[i][j]=INF;
if(i < j) continue;
ma = a[i];
for(int l = i-1;l>=1;l--){
dp[i][j] = min(dp[i][j],dp[l][j-1] + ma);
ma =max(ma,a[l]);
}
// cout << i << " " << j << " " << dp[i][j] << endl;
}
}
cout << dp[n][k] << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll tt=1;
// cin >> tt;
while(tt--){
solve();
}
}
# | 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... |