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 nl '\n'
#define pb push_back
#define E exit(0)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(s) (s).size()
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int N=1e6+5;
const int INF=1e9+7;
const int eps=1e-6;
int mn=INF,a[101],n;
void rec (int pos, int k, int mx=0, int sum=0) {
if (pos>n && k!=0) return;
if (pos>n && k==0) { mn=min(mn,sum); return; }
if (k<0) return;
rec(pos+1,k-1,a[pos],sum+a[pos]);
rec(pos+1,k,max(mx,a[pos]),sum-mx+max(mx,a[pos]));
}
void solve() {
int k;
cin>>n>>k;
for (int i=1;i<=n;i++) {
cin>>a[i];
}
rec(1,k);
cout<<mn;
}
ll test=1;
int main () {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie();
// 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... |