1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << (x))
#define sz(x) (int)x.size()
#define fout(x) {cout << x << "\n"; return; }

using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1e5;
const int M = pw(16);
const long long mod = 1e9 + 7;
const int N = 5e5;
const ll inf = 1e18;
template <typename T> void vout(T s){cout << s << endl;exit(0);}

ll solve(vector <ll> a){
    ll n = a.size(), s = 0, ans = 0;
    for(auto i : a){
        s += i;
        ans = max(ans, s);
        s = max(0LL, s);
    }
    return ans;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("8.in", "r", stdin);

    int n, k;
    cin >> n >> k;

    vector <ll> a(n), b(n), c(n);

    for(int i = 0; i < n; i++){
        cin >> a[i];        
    }

    string s;

    for(int i = 0; i < n; i++){
        cin >> b[i];
        c[i] = b[i];
        s += "B";
    }


    ll ans = 0;

    for(int step = 0; step < k; step++){
        ll idx = -1, val = 1e18;
        for(int j = 0; j < n; j++) if(s[j] == 'B'){
            c[j] = a[j];
            ll x = solve(c);
            if(x <= val){
                val = x;
                idx = j;
            }
            c[j] = b[j];
        }
        c[idx] = a[idx];
        s[idx] = 'A';
    }

    cout << max(0LL, solve(c)) << "\n";
    cout << s << "\n";

    return 0;
}