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>
#define pb push_back
#define s second
#define f first
#define ll long long
using namespace std;
const int N = 100005;
int dp[N][105],a[N];
int main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,k;
cin>>n>>k;
for (int i = 1; i <= n; i++)
cin>>a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++){
for (int K = 2; K <= k; K++)
for (int j = K - 1; j < i; j++){
if (dp[i][K]) dp[i][K] = min(dp[i][K],dp[j][K - 1] + a[i]);
else dp[i][K] = dp[j][K - 1] + a[i];
}
dp[i][1] = a[i];
}
cout<<dp[n][k];
}
# | 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... |