제출 #345170

#제출 시각아이디문제언어결과실행 시간메모리
345170mansurK개의 묶음 (IZhO14_blocks)C++14
18 / 100
1082 ms364 KiB
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define fix fixed<<setprecision
#define pii pair<int,int>
#define E exit (0)
#define int long long
const int inf=1e9;
int c[100001],mn=inf,n;
void r(int pos,int k,int sum=0,int mx=0) {
	if (pos==n+1&&k>0) {
		return;
	}
	if (k==0&&pos==n+1) {
		mn=min(mn,sum);
		return;
	}
	if (k<0) {
		return;
	}
	r(pos+1,k-1,sum+c[pos],c[pos]);
	r(pos+1,k,sum-mx+max(mx,c[pos]),max(mx,c[pos]));
}
signed main() {
	//freopen("planting.in","r",stdin);
	//freopen("planting.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin>>n>>k;
	for (int i=1;i<=n;i++) {
		cin>>c[i];
	}
	r(1,k);         
	cout<<mn;
}         
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...