# B. Linguistics
link : https://codeforces.com/contest/1685/problem/B
tóm tắt đề : cho xâu toàn AB, hỏi có thể tách xâu ra thành a kí tự A, b kí tự B, c chữ AB và d chữ BA hay không
ý tưởng : tham lam dựa trên dãy ..ABABAB..
code AC :
:::spoiler
```cpp
#include<bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rev(i, a, b) for (int i = (a); i >= (b); --i)
#define ll long long
using namespace std;
const int mxn = 2e5 + 8;
int n;
string s;
bool cmp(int a, int b)
{
return (a > b);
}
int main(){
//freopen("D:\\test.txt", "r", stdin);
//freopen("D:\\test2.txt", "w", stdout);
int t; cin >> t;
while(t--)
{
int a, b, c, d, cntA = 0, cntB = 0;
cin >> a >> b >> c >> d;
cin >> s;
n = s.length();
rep(i, 1, n) if (s[i - 1] == 'A') ++cntA;
else ++cntB;
if (cntA != a + c + d || cntB != b + c + d)
{
cout << "NO\n";
continue;
}
vector<int> tap1, tap2, tap3;
int p = 0;
while(p < n - 1)
{
if (s[p + 1] == s[p])
{
++p;
continue;
}
int i = p + 1;
while(i < n - 1 && s[i + 1] != s[i]) ++i;
if (s[p] != s[i])
{
if (s[p] == 'A') tap1.push_back((i - p + 1)/2);
else tap2.push_back((i - p + 1)/2);
}
else tap3.push_back((i - p)/2);
p = i + 1;
}
//for (int x : tap2) cout << x << ' '; cout << endl;
sort(tap1.begin(), tap1.end(), cmp);
while(c > 0 && tap1.size())
{
int x = tap1.back(); tap1.pop_back();
int t = min(x, c);
x -= t;
c -= t;
if (x > 1) tap1.push_back(x);
}
while(c > 0 && tap3.size())
{
int x = tap3.back(); tap3.pop_back();
int t = min(x, c);
x -= t;
c -= t;
if (x > 0) tap3.push_back(x);
}
sort(tap2.begin(), tap2.end());
while(c > 0 && tap2.size())
{
int x = tap2.back(); tap2.pop_back();
int t = min(x - 1, c);
x -= t + 1;
c -= t;
if (x > 0) tap2.push_back(x);
}
if (c > 0)
{
cout << "NO\n";
continue;
}
//for (int x : tap2) cout << x << ' '; cout << endl;
for (int x : tap1) d -= x - 1;
for (int x : tap2) d -= x;
for (int x : tap3) d -= x;
if (d > 0)
{
cout << "NO\n";
continue;
}
cout << "YES\n";
}
}
```
:::