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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1588>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    int N,M,K; cin >> N >> M >> K;
    vector<ll> a(N),b(N);
    for(auto& in:a) cin >> in;
    for(auto& in:b) cin >> in;
    for(int i = 0; i < (1<<N);i++){
        if(__builtin_popcount(i) > K) continue;
        vector<pll> score;
        for(int j = 0; j < N;j++){
            if((i>>j)&1){
                score.push_back(make_pair(a[j],b[j]));
            }
        }
        sort(score.rbegin(),score.rend());
        ll T = 0,L = M;
        for(auto p:score){
            T += min(L,p.second)*p.first;
            L -= min(L,p.second);
        }
        res = max(res,T+L);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

pii f[19];

int main(){
	int n=read(),m=read(),k=read();
	REP(i,n)f[i].first=read();
	REP(i,n)f[i].second=read();
	sort(f,f+n,greater<pii>());
	int ans=0;
	FOR(bits,1,(1<<n)){
		int rem=m,s=0,w=0;
		REP(i,n)if((bits>>i)&1){
			if((++s)>k)
				break;
			int u=min(rem,f[i].second);
			w+=f[i].first*u;
			rem-=u;
		}
		ans=max(ans,w+rem);
	}
	cout<<ans<<endl;
}

C++: #include <iostream>
#include <vector>

template<class T>
using vec = std::vector<T>;

int rec(int S, int N, int K, int money, vec<int> &a, vec<int> &b)
{
    if (__builtin_popcount(S) == K) {
        return money;
    }
    
    int res = 0;
    for (int i = 0; i < N; i++) {
        if (S >> i & 1) continue;
        int m = std::min(b[i], money);
        res = std::max(res,
                  rec(S | (1 << i), N, K, money - m, a, b) + a[i] * m);
    }
    return res;
}

int main()
{
    int N, M, K;
    std::cin >> N >> M >> K;
    
    vec<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    
    for (int i = 0; i < N; i++) {
        std::cin >> b[i];
    }
    
    std::cout << rec(0, N, K, M, a, b) << std::endl;
    return 0;
}

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];
    }
    int foo = M;
    while(foo > 0) {
      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;
      cost += curr;
      for(int i = 0; i < N; i++) {
        if((k >> i) & 1 && C[i] > 0 && A[i] == curr) {
          --C[i];
          --foo;
          break;
        }
      }
    }
    ret = max(ret, cost + foo);
  }
  cout << ret << endl;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, m, k;
int a[15], b[15];
P c[15];

int main(){
	cin >> n >> m >> k;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) c[i] = P(a[i],b[i]);
    int ans = 0;
    sort(c,c+n);
    rep(i,(1<<n)){
        int fl = 0, ii = i;
        vector<P> tmp;
        rep(j,n){
            if(ii&1){
                fl++;
                tmp.push_back(c[j]);
            }
            ii >>= 1;
        }
        if(fl > k) continue;
        sort(tmp.begin(),tmp.end(),greater<P>());
        int mm = m, cnt = 0;
        rep(j,tmp.size()){
            cnt += tmp[j].first*min(mm,tmp[j].second);
            mm -= tmp[j].second;
            if(mm <= 0) break;
        }
        ans = max(ans,cnt+mm);
    }
    cout << ans << endl;
}