Untitled

Anonymous
plain_text
02/14/2026 12:24 PM
1.7 KB
12
Indexable
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define el '\n'

void IOF() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}

void solve() {
    ll n, x, y;
    cin >> n >> x >> y;
    string s;
    cin >> s;
    vector<ll> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    ll suma = 0, sumb = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') sumb += p[i];
        else suma += p[i];
    }
    if (suma == x && sumb == y) {
        cout << "YES";
        return;
    }
    if (suma >= x && sumb >= y) {
        cout << "NO";
        return;
    }
    ll c = 0;
    if (suma >= x && sumb <= y) {
        for (int i = 0; i < n; i++)
            if (s[i] == '0')
                c += p[i] / 2;
    } else {
        for (int i = 0; i < n; i++)
            if (s[i] != '0')
                c += p[i] / 2;
    }
    cout << ((abs(y - sumb) == abs(x - suma) && c >= abs(y - sumb)) ? "YES" : "NO");
}

int main() {
    IOF();
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
        cout << el;
    }
    return 0;
}
Editor is loading...
Leave a Comment