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;

int n,m,k;

struct P{
    int a,b;
    bool operator<(P rhs){
        return a>rhs.a;
    }
};

vector<P> ps;

int calc(vector<P> ptmp){
    sort(ptmp.begin(),ptmp.end());
    int res=0;
    int rest=m;
    for(int i=0;i<k;i++){
        int tmp=min(rest,ptmp[i].b);
        res+=tmp*ptmp[i].a;
        rest-=tmp;
    }
    return res+rest;
}
int dfs(int cnt,int id,vector<P>& ptmp){
    if(cnt==k) return calc(ptmp);
    int res=0;
    for(int i=id+1;i<n;i++){
        ptmp.push_back(ps[i]);
        res=max(res,dfs(cnt+1,i,ptmp));
        ptmp.pop_back();
    }
    return res;
}
int main(){
    cin>>n>>m>>k;
    ps.resize(n);

    for(int i=0;i<n;i++) cin>>ps[i].a;
    for(int i=0;i<n;i++) cin>>ps[i].b;

    vector<P> ptmp;
    cout<<dfs(0,-1,ptmp)<<endl;
    return 0;
}

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;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
typedef pair<int, int> pii;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    vector<int> used(n, 0);
    for (int i = 0; i < k; i++) {
        used[i] = 1;
    }
    sort(all(used));
    int ans = 0;
    do{
        int tm = m;
        vector<pii> poteto;
        for(int i = 0; i < n; i++){
            if(used[i] == 1)poteto.push_back(pii(a[i], b[i]));
        }
        sort(all(poteto));
        reverse(all(poteto));
        int tmp = 0;
        for (int i = 0; i < poteto.size() and tm > 0; i++) {
            tmp += poteto[i].first*min(tm, poteto[i].second);
            tm -= min(poteto[i].second, tm);
        }
        ans = max(ans, tmp + tm);
    }while(next_permutation(all(used)));
    cout << ans << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define ALL(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef pair<ut,ut> pr;
typedef vector<ut> VI;
typedef vector<pr> Vpr;
const int SIZE=100;
Vpr ab;
int a[SIZE],b[SIZE];
int N,M,K;
int solve(int now,int able,int m){
	int ans=0;
	if(now==N) return m;
	if(able){
		int used=min(m,ab[now].second);
	    int getP=used*ab[now].first;
		ans=solve(now+1,able-1,m-used)+getP;
	//	cout << getP << endl;
	}
	return max(solve(now+1,able,m),ans);
}
int main(){
	
	cin >> N >> M >> K;
	REP(i,N){
		cin >> a[i];
	}
	REP(i,N){
		cin >> b[i];
	}
	REP(i,N){
		ab.PB(pr(a[i],b[i]));
	}
	sort(ALL(ab),greater<pr>());
	cout << solve(0,K,M) << endl;
	return 0;
}