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

Python: n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
abList = sorted(tuple(zip(aList, bList)), key=lambda x:-x[0])
ans = 0
#dp[y][x] ... y面x個の最大値
dp = [[0] * (m + 1) for _ in range(k + 1)]
for a, b in abList:
    for y in range(k - 1, -1, -1):
        for x in range(m - 1, -1, -1):
            use = min(b, m - x)
            dp[y + 1][x + use] = max(dp[y + 1][x + use], dp[y][x] + use * a)

ans = 0
for y in range(k + 1):
    for x in range(m + 1):
        ans = max(ans, dp[y][x] + m - x)
print(ans)

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first1,
	BidirectionalIterator last1,
	BidirectionalIterator first2,
	BidirectionalIterator last2)
{
	if ((first1 == last1) || (first2 == last2)) {
		return false;
	}
	BidirectionalIterator m1 = last1;
	BidirectionalIterator m2 = last2; --m2;
	while (--m1 != first1 && !(*m1 < *m2)) {
	}
	bool result = (m1 == first1) && !(*first1 < *m2);
	if (!result) {
		// ???
		while (first2 != m2 && !(*m1 < *first2)) {
			++first2;
		}
		first1 = m1;
		std::iter_swap(first1, first2);
		++first1;
		++first2;
	}
	if ((first1 != last1) && (first2 != last2)) {
		// ???
		m1 = last1; m2 = first2;
		while ((m1 != first1) && (m2 != last2)) {
			std::iter_swap(--m1, m2);
			++m2;
		}
		// ??¢
		std::reverse(first1, m1);
		std::reverse(first1, last1);
		std::reverse(m2, last2);
		std::reverse(first2, last2);
	}
	return !result;
}

template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first,
	BidirectionalIterator middle,
	BidirectionalIterator last)
{
	return next_combination(first, middle, middle, last);
}

int main() {
	int N,M,K;cin>>N>>M>>K;
	vector<int>as(N),bs(N);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int j = 0; j < N; ++j) {
		cin>>bs[j];
	}
	vector<int>perms(N);
	iota(perms.begin(),perms.end(),0);
	int ans=0;
	do {
		do {
			int nans=0;
			int rest(M);
			for (int i = 0; i < K; ++i) {
				int use=min(rest,bs[perms[i]]);
				nans+=use*as[perms[i]];
				rest-=use;
			}
			nans+=rest;
			ans=max(ans,nans);
		}while(next_permutation(perms.begin(),perms.begin()+K));
	}while(next_combination(perms.begin(),perms.begin()+K,perms.end()));
	cout<<ans<<endl;
	return 0;
}

C++: #include <iostream>
using namespace std;

typedef struct {
    int a,b;
}poteinfo;

int main(){
    int a,b,c,n,m,tm,k,t,maxc=0;
    poteinfo pi[15];
    
    cin >> n >> m >> k;
    
    for (int i=0;i<n;i++) cin >> pi[i].a;
    for (int i=0;i<n;i++) cin >> pi[i].b;
    
    if (n==1) {
        for (a=0;a<n;a++){
            t=0;
            tm=m;
            if (pi[a].b<=tm){
                t+=pi[a].a*pi[a].b;
                tm-=pi[a].b;
            }
            t+=tm;
            if (maxc < t) maxc=t;
        }
    }else if(n==2){
        for (a=0;a<n;a++){
            t=0;
            tm=m;
            if (pi[a].b<=tm){
                t+=pi[a].a*pi[a].b;
                tm-=pi[a].b;
            }
            for (b=0;b<n;b++){
                if (k<2) break;
                if (a!=b && pi[b].b<=tm){
                    t+=pi[b].a*pi[b].b;
                    tm-=pi[b].b;
                }
            }
            t+=tm;
            if (maxc < t) maxc=t;
        }
    }else{
        for (a=0;a<n;a++){
            for (b=0;b<n;b++){
                for (c=0;c<n;c++){
                    t=0;
                    tm=m;
                    if (pi[a].b<=tm){
                        t+=pi[a].a*pi[a].b;
                        tm-=pi[a].b;
                    }
                    if (k>=2) {
                        if (a!=b && pi[b].b<=tm){
                            t+=pi[b].a*pi[b].b;
                            tm-=pi[b].b;
                        }
                    }
                    if (k>=3) {
                        if (a!=c && b!=c && pi[c].b<=tm){
                            t+=pi[c].a*pi[c].b;
                            tm-=pi[c].b;
                        }
                    }
                    t+=tm;
                    if (maxc < t) maxc=t;
                }
            }
        }
    }
    
    cout << maxc << endl;
    
    return 0;
}