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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 60


int main(){
  int n,m,k;
  int a[SIZE],b[SIZE];

  scanf("%d%d%d",&n,&m,&k);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  for(int i=0;i<n;i++) scanf("%d",b+i);
  

  
  ll ans = 0;
  
  for(int i=1;i<(1<<n);i++){
    if(__builtin_popcount(i) > k) continue;
    
    vector<pair<int,int> > vec;
    
    for(int j=0;j<n;j++){
      if(i & (1<<j)) vec.push_back({a[j],b[j]});
    }
    sort(vec.begin(),vec.end(),greater<pair<int,int> >());

    ll calc = 0;
    int t = m;
    for(int j=0;j<vec.size();j++){
      calc += vec[j].first * min(t,vec[j].second);
      t -= min(t,vec[j].second);
    }
    
    ans = max(ans,calc+t);
  }

  printf("%lld\n",ans);
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <set>

using namespace std;
typedef pair<int,int> P;

int a[15];
int b[15];
int dp[16][10001]; //[????????°][????????°]->??????
set<P> S;

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

    for(int i=1;i<=N;i++){
        int ai=a[i-1],bi=b[i-1];
        for(int k=i;k>0;k--){
            S.clear();
            for(int n=0;n<bi;n++) S.insert(P(dp[k-1][10000-n]+n*ai,10000-n));
            for(int m=10000;m>=0;m--){
                S.erase(P(dp[k-1][m+1]+(10000-m-1)*ai,m+1));
                if(m-bi>=0) S.insert(P(dp[k-1][m-bi]+(10000-m+bi)*ai,m-bi));
                int maximum=(*S.rbegin()).first-(10000-((*S.rbegin()).second))*ai+(m-(*S.rbegin()).second)*ai;
                dp[k][m]=max(dp[k][m],maximum);
            }
        }
    }
    int ans=0;
    for(int m=0;m<=M;m++) ans=max(ans,dp[K][m]+M-m);
    cout<<ans<<endl;
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <string>
#include <complex>
#include <cstdio>
using namespace std;

pair<int,int> a[15];

int main(){
	int n,m,K;
	cin >> n >> m >> K;
	long long sum = 0;
	for(int i = 0 ; i < n ; i++) cin >> a[i].first;
	for(int i = 0 ; i < n ; i++) cin >> a[i].second;
	long long w = 0;
	for(int k = 0 ; k < (1<<n) ; k++){
		if( __builtin_popcount(k) > K ) continue;
		vector<int> v;

		for(int i = 0 ; i < n ; i++){
			if( k >> i & 1 )
				for(int j = 0 ; j < a[i].second ; j++)
					v.push_back(a[i].first);
		}
		sort(v.rbegin(),v.rend());

		long long s = m - min<int>(v.size(),m);
		for(int i = 0 ; i < min<int>(v.size(),m) ; i++){
			//cout << v[i] << endl;
			s += v[i];
		}
		w = max(w,s);

	}
	cout << w << endl;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int main()
{
  int N, M, K, A[15], B[15], C[15];
  cin >> N >> M >> K;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }
  int ret = 0;
  for(int k = 0; k < (1 << N); k++) {
    if(__builtin_popcount(k) > K) continue;
    int cost = 0;
    for(int i = 0; i < N; i++) {
      C[i] = B[i];
    }
    for(int j = 0; j < M; j++) {
      int curr = 0;
      for(int i = 0; i < N; i++) {
        if((k >> i) & 1 && C[i] > 0) {
          curr = max(curr, A[i]);
        }
      }
      if(curr == 0) break;
      for(int i = 0; i < N; i++) {
        if((k >> i) & 1 && C[i] > 0 && A[i] == curr) {
          --C[i];
          cost += A[i];
          break;
        }
      }
    }
    ret = max(ret, cost);
  }
  cout << ret << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl;
#define SZ(a) (int)a.size()
using LL = long long; template<class T> using V = vector <T>; template <class T> using VV = V<V<T>>;


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, M, K; cin >> N >> M >> K;
	V<int>a(N), b(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	FOR(i, 0, N) {
		cin >> b[i];
	}
	LL ans = 0;
	FOR(state, 0, 1 << N) {
		if (__builtin_popcount(state) > K)continue;
		LL ret = 0;
		V<int>ord;
		FOR(i, 0, N) {
			if (state & 1 << i)
				ord.push_back(i);
		}
		do {
			LL sub = 0;
			int MM = M;
			FOR(i, 0, SZ(ord)) {// M個植えれる
				LL sz = min(MM, b[ord[i]]);
				MM -= sz;
				sub += sz * a[ord[i]];
			}
			sub += MM;
			ret = max(ret, sub);
		} while (next_permutation(ALL(ord)));

		ans = max(ans, ret);
	}
	
	cout << ans << endl;

	return 0;
}