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 <iostream>
using namespace std;

typedef struct {
    int a,b;
}poteinfo;

int main(){
    int a,b,c,n,m,tm,k,t,maxc;
    poteinfo pi[15];
    int ma,mb,mc;
    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;
    
    maxc=m;
    
    if (n==1) {
        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++){
            for (b=0;b<n;b++){
                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;
                    }
                }
                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;
                        ma=a;
                        mb=b;
                        mc=c;
                    }
                }
            }
        }
    }
    
    cout << maxc << endl;
    
    return 0;
}