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
83
84
#include <bits/stdc++.h>
using namespace std;
priority_queue <pair<int,pair<int,int> > > pq;
int a[100009] {};
int b[100009] {};
int kto[100009] {};
int wart[100009] {};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int n,d=0,ka,kb;
long long mmax=INT_MIN,x=0;
pair <int,pair<int,int> > obr;

cin>>n>>ka;
kb=n-ka;
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++)
{
if (a[i]>b[i])
{d=a[i]-b[i];
if (d<0) {d=0;}
pq.push({d,{i,3}});}

else
{d=b[i]-a[i];
if (d<0) {d=0;}
pq.push({d,{i,2}});}
}

while (kb>0 && ka>0)
{
obr=pq.top();
kto[obr.second.first]=obr.second.second;
if (obr.second.second==2) {ka--;}
else {kb--;}
pq.pop();
}

if (kb>0)
{
for (int i=0;i<n;i++)
{if (kto[i]==0)
kto[i]=3;}
}
else
{
for (int i=0;i<n;i++)
{if (kto[i]==0)
{kto[i]=2;}
}
}

for (int i=0;i<n;i++)
{
if (kto[i]==2)
{wart[i]=a[i];}
else {wart[i]=b[i];}
}

for (int i=0;i<n;i++)
{x=x+wart[i];
if (x<0)
{x=0;}
if (mmax<x)
mmax=x;
}
cout<<mmax<<"\n";

for (int i=0;i<n;i++)
{if (kto[i]==2)
{cout<<"A";}
else {cout<<"B";}}

return 0;
}