这题的重点是发现规律,需要手动推导出A要从小开始

#include <bits/stdc++.h>
using namespace std;
struct nodea {//a道具,id表示道具,w是增加量
    int id, w;//id把输入的编号纪录住了!!!
}a[100005];
struct nodeb {//b道具
    int id, w;
}b[100005];
bool cmp1(nodea a, nodea b)//同时给对应的编号记录!!!!!!!
{
    if (a.w != b.w) return a.w < b.w;//先对A的增加量排序,从小到大
    else return a.id < b.id;//再按字典序id排序
}
bool cmp2(nodeb a, nodeb b)
{
    if (a.w != b.w)  return a.w > b.w;
    else return a.id < b.id;
}
int main()
{
    int n1, n2;
    cin >> n1 >> n2;
    for (int i = 1; i <= n1; i++) cin >> a[i].w, a[i].id = i;
    for (int i = 1; i <= n2; i++) cin >> b[i].w, b[i].id = i;
    sort(a + 1, a + 1 + n1, cmp1);
    sort(b + 1, b + n2 + 1, cmp2);
    string s;
    cin >> s;//输入字符串
    int idx1, idx2;
    idx1 = idx2 = 1;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '1') {
            cout << "B";
            cout << b[idx1++].id << endl;//此时未排序前对应的下标已经排序好了,直接自增就行
        }
        else {
            cout << "A";
            cout << a[idx2++].id << endl;
        }
    }
    cout << "E" << endl;
    return 0;
}