ソースコード
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
map<int, int> dp[18][100000];
int main() {
int n, k, b;
cin >> n >> k >> b;
VI a(n);
REP(i,n) a[i] = in();
dp[0][0][0] = 0;
REP(x,k) REP(mask,1<<n) for(P p : dp[x][mask]) {
REP(i,n){
if ((mask >> i) & 1) continue;
int next = mask | (1 << i);
if (p.first + a[i] <= b){
if (!dp[x+1][next].count(0) || dp[x+1][next][0] > p.second) dp[x+1][next][0] = p.second;
}
if (p.first + a[i] < b){
if (!dp[x][next].count(p.first + a[i]) || dp[x][next][p.first + a[i]] > p.second + 1){
dp[x][next][p.first + a[i]] = p.second + 1;
}
}
if (p.first + a[i] > b){
if (!dp[x+1][next].count(p.first + a[i] - b) || dp[x+1][next][p.first + a[i] - b] > p.second + 1){
dp[x+1][next][p.first + a[i] - b] = p.second + 1;
}
if (!dp[x+2][next].count(0) || dp[x+2][next][0] > p.second) dp[x+2][next][0] = p.second;
}
}
}
int ans = 100;
REP(x,k+1){
for (P p : dp[x][(1<<n)-1]) if (x < k || p.first == 0) ans = min(ans, p.second);
}
cout << ans << endl;
return 0;
}