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 <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

long long gcd(long long a, long long b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        long long r = a%b;
        a=b;
        b=r;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //x???n???????¨????????????????n??????2?????¨?¨???????????¨????
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//???????????????
        }
        x=(x*x)%mod;//2???
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int a=0;
    int b=0;
};

class xxIntu {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //?¬¬2?????¶
        if(riLeft.a != riRight.a){
            return riLeft.b < riRight.b;//>:??????(?°?????????????????????????)???<:??????(??§????????????????????????)
        }
        //?¬¬1?????¶
        return riLeft.a < riRight.a;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/

int funC(int a,int b){
    int tmp=1;
    int tmp2=1;
    for(int i=0;i<b;i++){
        tmp=tmp*(a-i);
        tmp2=tmp2*(b-i);
    }
    return tmp/tmp2;
}

int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //???????????¨
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //????????????

    int N,M,K;
    cin >> N >> M >> K;
    XX x[15];
    int b[15];
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        x[i].a=tmp;
    }
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        x[i].b=tmp;
    }

    int ans=0;
    
    for(int i=0;i<1<<N;i++){
        vector<XX> hatake;
        hatake.clear();
        int tmp=0;
        for(int j=0;j<N;j++){
            if(i>>j & 1){
                hatake.push_back(x[j]);
            }
        }
        if(hatake.size()<=K){
            sort(hatake.begin(),hatake.end(),xxIntu());
            int ko=M;
            int i=0;
            while(ko!=0 && i<hatake.size()){
                if(hatake[i].b<=ko){
                    tmp=tmp+hatake[i].b*hatake[i].a;
                    ko-=hatake[i].b;
                }else{
                    tmp=tmp+ko*hatake[i].a;
                    ko=0;
                    break;
                }
                i++;
            }
            tmp=tmp+ko;
        }
        if(ans<tmp){
            ans=tmp;
        }
    }
    
    cout << ans << endl;

    
    //???????????§
    //cout << "ans" << endl;????????????
    //printf("%.0f\n",ans);//?°???°?????\?????¨?????????
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

ll max(ll a,ll b){
	return (a>b)?a:b;
}

ll min(ll a,ll b){
	return (a>b)?b:a;
}

int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n],b[n];
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	ll ans=0;
	if(k==1){
		rep(i,n)ans=max(ans,a[i]*min(m,b[i])+max(0,m-b[i]));
	}else if(k==2){
		rep(i,n){
			rep(j,n){
				if(i==j)continue;
				ans=max(ans,a[i]*min(m,b[i])+a[j]*min(max(0,m-b[i]),b[j])+max(0,m-b[i]-b[j]));
			}
		}
	}else{
		rep(i,n){
			rep(j,n){
				rep(l,n){
					if((i==j) || (j==l) || (l==i))continue;
					ans=max(ans,a[i]*min(m,b[i])+a[j]*min(max(0,m-b[i]),b[j])+a[l]*min(max(0,m-b[i]-b[j]),b[l])+max(0,m-b[i]-b[j]-b[l]));
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int N,M,K;
int a[20],b[20];


int main(){
  cin>>N>>M>>K;
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }

  b[N]=b[N+1]=b[N+2]=M;
  
  int ans=M;


  for(int i=0;i<N+3;i++){
    for(int j=0;j<N+3;j++){
      if(i==j)continue;
      for(int k=0;k<N+3;k++){
        if(i==k||j==k)continue;
        int tmp=M;

        int ai=min(tmp,b[i]);
        tmp-=ai;
        if(K>=1){
          int value = tmp + ai*a[i];
          ans=max(ans, value );
        }
        
        int aj=min(tmp,b[j]);
        tmp-=aj;
        if(K>=2){
          int value = tmp + ai*a[i] + aj*a[j];
          ans=max(ans, value );
        }
        
        int ak=min(tmp,b[k]);
        tmp-=ak;
        if(K==3){
          int value = tmp + ai*a[i] + aj*a[j] + ak*a[k];
          ans=max(ans, value );
        }

      }
    }
  }
  
  cout<<ans<<endl;
  return 0;
}