Submission #1127412

#TimeUsernameProblemLanguageResultExecution timeMemory
1127412FucKanhBank (IZhO14_bank)C++20
44 / 100
137 ms25068 KiB
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int,int>

using namespace std;

int n,m;
int w[1<<21], pos[1<<21];
int a[30], b[30], s[30];

void solve() {
    cin >> n >> m;
    if (n > m) {
        cout << "NO";
        return;
    }

    memset(pos,-1,sizeof(pos));
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) s[i] = s[i-1] + a[i];
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        pos[1<<i-1] = 0;
    }

    for (int state = 1; state < (1<<m); state++) {
        for (int i = 0; i < m; i++) {
            if ((state & (1<<i))==0) continue;
            w[state] += b[i+1];
        }
    }

    for (int state = 1; state < (1<<m); state++) {
        if (pos[state] == -1) continue;
//        cerr << bitset<6>(state) << ": " << w[state] << " " << pos[state] << endl;
        if (pos[state] == n) {
            cout << "YES";
            return;
        }
        for (int i = 0; i < m; i++) {
            if (state & (1<<i)) continue;
            if (w[state ^ (1<<i)] == s[pos[state] + 1]) pos[state ^ (1<<i)]= max(pos[state ^ (1<<i)], pos[state] + 1);
            else if (w[state ^ (1<<i)] < s[pos[state] + 1]) pos[state ^ (1<<i)]= max(pos[state ^ (1<<i)], pos[state]);
        }
    }
    cout << "NO";
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...