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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;

int pc(int n) {
    return n ? n % 2 + pc(n / 2) : 0;
}

int main() {
    int n, m, k;
    while (cin >> n >> m >> k) {
        pair<int, int> p[20];
        for (int i = 0; i < n; i++) {
            cin >> p[i].first;
        }
        for (int i = 0; i < n; i++) {
            cin >> p[i].second;
        }
        sort(p, p + n);
        reverse(p, p + n);
        int ans = 0;
        for (int S = 0; S < 1 << n; ++S) {
            if (pc(S) > k) continue;
            int rem = m;
            int get = 0;
            for (int i = 0; i < n; i++) {
                if (~S >> i & 1) continue;
                int take = min(rem, p[i].second);
                get += take * p[i].first;
                rem -= take;
            }
            ans = max(get+rem, ans);
        }
        cout << ans << endl;
    }
}

C++: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> va;
  vector<ll> vb;
  rep(i, 0, n) {
    ll a;
    cin >> a;
    va.pb(a);
  }
  rep(i, 0, n) {
    ll b;
    cin >> b;
    vb.pb(b);
  }
  ll mx = 0;
  rep(i, 0, 1 << n) {
    ll c = 0;
    vector<ll> va1;
    vector<ll> vb1;
    rep(j, 0, n) {
      if ((i >> j) & 1) {
        c++;
      }
    }
    if (c == k) {
      rep(j, 0, n) {
        if ((i >> j) & 1) {
          va1.pb(va[j]);
          vb1.pb(vb[j]);
        }
      }
      vector<pair<ll,ll> > v;
      rep(j,0,va1.sz){
        v.pb(mp(va1[j],vb1[j]));
      }
      sort(all(v));
      reverse(all(v));
      ll a1 = 0;
      ll m1 = m;
      rep(j,0,v.sz){
        a1 += v[j].fi*min(m1,v[j].se);
        m1-=v[j].se;
        if(m1<0)m1=0;
      }
      mx = max(mx,a1+m1);
    }
  }
  cout << mx << endl;
  return 0;
}

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

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

    //for(int i=0;i<n;i++)cout  << a[i] << " " << b[i]  << " " << a[i]*b[i]<< endl;

    int ma=0;
    if(k==3){
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                //if(i==j)continue;
                for(int l=j+1;l<n;l++){
                    //cout << i << " " << j << " " << l << endl;
                    //cout << a[i]*b[i] <<" "<< a[j]*b[j] <<" " << a[l]*b[l] << endl;
                    //if(l==i ||l==j )continue;
                    int sum=a[i]*b[i]+a[j]*b[j]+a[l]*b[l];
                    //cout << sum << endl;
                    if(b[i]+b[j]+b[l]>m)sum-=((b[i]+b[l]+b[j])-m)*min(a[i],min(a[j],a[l]));
                    else sum+=m-(b[i]+b[j]+b[l]);
                    if(sum>ma){
                       // cout << min(a[i],min(a[j],a[l])) << endl;
                        ma=sum;
                        //cout << i << " " << j <<" " << l << endl;
                    }
                }
            }
        }
    }else if(k==2){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                int sum=a[i]*b[i]+a[j]*b[j];
                if(b[i]+b[j]>m)sum-=(m-(b[i]+b[j]))*min(a[i],a[j]);
                else sum+=m-(b[i]+b[j]);
                if(sum>ma)ma=sum;
            }
        }
    }else{
        for(int i=0;i<n;i++){
            int sum=a[i]*b[i];
            if(b[i]>m)sum-=(m-b[i])*a[i];
            else sum+=m-b[i];
            if(ma<sum)ma=sum;
        }
    }

    cout << ma << endl;

}

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

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<pair<int,int>> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i].first;
    for(int i = 0; i < n; i++)  cin >> v[i].second;
    int ans = 0;
    for(int i = 1; i < 1<<n; i++){
        vector<pair<int,int>> vp;
        for(int j = 0; j < n; j++){
            if((i>>j)&1)    vp.push_back(v[j]);
        }
        if(vp.size() > k)   continue;
        sort(vp.rbegin(), vp.rend());
        int tmp = 0, res = m;
        for(int i = 0; i < vp.size(); i++){
            int take = min(res, vp[i].second);
            tmp += take * vp[i].first;
            res -= take;
        }
        ans = max(ans, tmp+res);
    }
    cout << ans << endl;
    return 0;
}