Go: package main

import (
    "bufio"
    "os"
    "fmt"
    "strings"
    "strconv"
    "sort"
    "math"
)

/************** Input *************/
var sc = bufio.NewScanner(os.Stdin)

func ReadLineToInt () []int{
    sc.Scan()
    line := strings.Split(sc.Text(), " ")
    length := len(line)
    var intLine []int
    for i := 0;i < length; i++ {
        n, _ := strconv.Atoi(line[i])
        intLine = append(intLine, n)
    }
    return intLine
}

/************* Pairs **************/
type Pair struct {
    a int
    b int
}

type SortablePairs struct {
    arr []*Pair
    lessfunc []lessFunc
}

type lessFunc func(p *Pair, q *Pair)bool

func (sp SortablePairs) Len() int {
    return len(sp.arr)
}

func (sp SortablePairs) Swap(i ,j int) {
    sp.arr[i], sp.arr[j] = sp.arr[j], sp.arr[i]
}

func (sp SortablePairs) Less(i, j int) bool {
    p, q := sp.arr[i], sp.arr[j]
    for k := 0; k < len(sp.lessfunc); k++ {
        less := sp.lessfunc[k]
        if less(p, q) {
            return true
        } else if less(q, p) {
            return false
        }
    }
    return false
}

/***********  min, max  *************/
func min(a, b int) int {
    return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
    return int(math.Max(float64(a), float64(b)))
}


/************  main  ***************/
func main() {
    nmk := ReadLineToInt()
    n, m, k := nmk[0], nmk[1], nmk[2]
    aSlice := ReadLineToInt()
    bSlice := ReadLineToInt()
    sp := SortablePairs{}
    for i := 0; i < n; i++ {
        sp.arr = append(sp.arr, &Pair{a: aSlice[i], b: bSlice[i]})
    }

    sortFunc := func(p, q *Pair) bool {
        return p.a > q.a
    }

    sp.lessfunc = append(sp.lessfunc, sortFunc)
    sort.Sort(sp)

    var dp [4][10001]int
    for i := 0; i < n; i++ {
        item := sp.arr[i]
        a := item.a
        b := item.b
        for y := k - 1;y >= 0; y-- {
            for x := m - 1; x >= 0; x-- {
                use := min(b, m - x)
                dp[y + 1][x + use] = max(dp[y + 1][x + use], dp[y][x] + use * a)
            }
        }
    }
    var ans int
    for y := 0; y <= k; y++ {
        for x := 0; x <= m; x++ {
            ans = max(ans, dp[y][x] + m - x)
        }
    }
    fmt.Println(ans)
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
int a[25],b[25];

int main(){
  scanf("%d%d%d",&n,&m,&k);
  REP(i,n)scanf("%d",a+i);
  REP(i,n)scanf("%d",b+i);
  int ans = 0;
  REP(msk,1<<n){
    int cnt = __builtin_popcount(msk);
    if(cnt > k)continue;
    vector<pii> cand;
    REP(i,n)if((msk>>i)&1)cand.push_back(pii(a[i],b[i]));
    sort(ALL(cand));
    reverse(ALL(cand));
    int tmp = 0;
    int rest = m;
    REP(i,cand.size()){
      int use = min(rest,cand[i].second);
      rest -= use;
      tmp += use*cand[i].first;
    }
    CHMAX(ans,tmp+rest);
  }
  printf("%d\n",ans);
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template<typename T> using Graph = vector<vector<T>>;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N, M, K;
    cin >> N >> M >> K;
    vi a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    int ans = -1;
    rep(s, 1 << N) {
        if (__builtin_popcount(s) != K) {
            continue;
        }
        vector<Pii> vp;
        rep(i, N) {
            if ((s >> i) & 1) {
                vp.emplace_back(a[i], b[i]);
            }
        }
        sort(all(vp));
        reverse(all(vp));
        int tmp = 0;
        int res = M;
        for (auto p : vp) {
            int a, b;
            tie(a, b) = p;
            tmp += a * min(res, b);
            res -= min(res, b);
        }
        ans = max(ans, tmp + res);
    }
    cout << ans << endl;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int bit_count(int N) {
	int cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

signed main(void) {
	int i, j, k, l;
	int N, M, K;
	int a[18], b[18];
	cin >> N >> M >> K;
	rep(i, N) cin >> a[i];
	rep(i, N) cin >> b[i];

	int mask;
	int cnt = 0;
	rep(mask, 1 << N) {
		int mask_cnt = 0;
		vector<pair<int,int>> mask_pr;
		if (bit_count(mask) != K) continue;
		rep(i, N) {
			if ((mask >> i) & 1) {
				mask_pr.push_back({ a[i],b[i] });
			}
		}
		int cur_poteto = M;
		sort(ALL(mask_pr));
		for(i=K-1;i>-1;i--) {
			mask_cnt += mask_pr[i].first * min(mask_pr[i].second, cur_poteto);
			cur_poteto -= mask_pr[i].second;
			if (cur_poteto < 0) break;
		}
		mask_cnt += max(cur_poteto, 0);
		if (cnt < mask_cnt) {
			//cerr << "!";
			//rep(i, K) {
			//	cerr << mask_pr[i].first << " ";
			//}
			//dump(mask_cnt);
			cnt = mask_cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}