이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |