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>
#include<algorithm>
using namespace std;

int main(){
  
  int n, m, k, a[20], b[20], ma=0;

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

  if(k==1){
    for(int i=0;i<n;i++){
      if(m<b[i]) ma=max(ma, a[i]*m); 
      else ma=max(ma, a[i]*b[i]+(m-b[i]));
    }
  }else if(k==2){
    for(int i=0;i<n;i++){
      int sum1=0, x;
      if(m<b[i]){
	sum1+=a[i]*m;
	x=m-m;
      }else{
	sum1+=a[i]*b[i];
	x=m-b[i];
      }
      for(int j=0;j<n;j++){
	int sum2=sum1;
	if(i==j) continue;
	if(x<b[j]){
	  sum2+=a[j]*x;
	  ma=max(ma, sum2);
	}else{
	  sum2+=a[j]*b[j];
	  ma=max(ma, sum2+(x-b[j]));
	}
      }
    }
  }else if(k==3){
    for(int i=0;i<n;i++){
      int sum1=0, x;
      if(m<b[i]){
	sum1+=a[i]*m;
	x=m-m;
      }else{
	sum1+=a[i]*b[i];
	x=m-b[i];
      }
      for(int j=0;j<n;j++){
	int sum2=sum1, y;
	if(x<b[j]){
	  sum2+=a[j]*x;
	  y=x-x;
	}else{
	  sum2+=a[j]*b[j];
	  y=x-b[j];
	}
	for(int l=0;l<n;l++){
	  int sum3=sum2;
	  if(i==j||i==l||j==l) continue;
	  if(y<b[l]){
	    sum3+=a[l]*y;
	    ma=max(ma, sum3);
	  }else{
	    sum3+=a[l]*b[l];
	    ma=max(ma, sum3+(y-b[l]));
	  }
	}
      }
    }
  }
    
  cout<<ma<<endl; 
  
  
  return 0;
}

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

int main()
{
  int n,m,k;
  pair<int,int> p[20];
  int a,b,c;
  int i,j,l;

  cin>>n>>m>>k;

  for(i=0;i<n;i++)
    cin>>p[i].first;
  for(i=0;i<n;i++)
    cin>>p[i].second;

  sort(p,p+n);

  if(k==1){
    a=min(m,p[n-1].second);
    cout<<p[n-1].first*a+m-a<<endl;;

  }else if(k==2){ 

    long long dp[20][20]={};
    long long ans=0;
    for(i=0;i<n-1;i++)
      for(j=i+1;j<n;j++){
	a=min(p[j].second,m);
	b=min(p[i].second,m-a);
	dp[i][j]=p[j].first*a+p[i].first*b;
	ans=max(ans,dp[i][j]+m-a-b);
      }
    cout<<ans<<endl;


  }else if(k==3){

    long long dp[20][20][20]={};
    long long ans=0;

    for(i=0;i<n-2;i++)
      for(j=i+1;j<n-1;j++)
	for(l=j+1;l<n;l++){
	  a=min(p[l].second,m);
	  b=min(p[j].second,m-a);
	  c=min(p[i].second,m-a-b);
	  dp[i][j][l]=p[l].first*a+p[j].first*b+p[i].first*c;
	  ans=max(ans,dp[i][j][l]+m-a-b-c);

	}

    cout<<ans<<endl;
  }

}

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

int main()
{
  int n,m,k;
  pair<int,int> p[20];
  int a,b,c;
  int i,j,l;

  cin>>n>>m>>k;

  for(i=0;i<n;i++)
    cin>>p[i].first;
  for(i=0;i<n;i++)
    cin>>p[i].second;

  sort(p,p+n);

  if(k==1){
    a=min(m,p[n-1].second);
    cout<<p[n-1].first*a+m-a<<endl;;

  }else if(k==2){ 

    long long dp[20][20]={};
    int ans=0;
    for(i=0;i<n-1;i++)
      for(j=i+1;j<n;j++){
	a=min(p[j].second,m);
	b=min(p[i].second,m-a);
	dp[i][j]=p[j].first*a+p[i].first*b;
	ans=max(ans,dp[i][j]+m-a-b);
      }
    cout<<ans<<endl;


  }else if(k==3){

    long long dp[20][20][20]={};
    int ans=0;

    for(i=0;i<n-2;i++)
      for(j=i+1;j<n-1;j++)
	for(l=j+1;l<n;l++){
	  a=min(p[l].second,m);
	  b=min(p[j].second,m-a);
	  c=min(p[i].second,m-a-b);
	  dp[i][j][l]=p[l].first*a+p[j].first*b+p[i].first*c;
	  ans=max(ans,dp[i][j][l]+m-a-b-c);

	}

    cout<<ans<<endl;
  }

}

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(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(m-b[i],b[j])+a[l]*min(m-b[i]-b[j],b[l])+max(0,m-b[i]-b[j]-b[l]));
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,k;
P farm[15];
int dp[10001][4];

int func(int v,int rest,int used){
	if(v==n || used==k)return rest;
	int res=max(rest,func(v+1,rest,used));
	int add=min(farm[v].second,rest)*farm[v].first;
	return max(res,func(v+1,rest-min(farm[v].second,rest),used+1)+add);
}

int main(void){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&farm[i].first);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&farm[i].second);
	}
	sort(farm,farm+n,greater<P>());
	printf("%d\n",func(0,m,0));
	return 0;
}