Submission #1127417

#TimeUsernameProblemLanguageResultExecution timeMemory
1127417FucKanhBank (IZhO14_bank)C++20
100 / 100
162 ms33264 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], ok[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]; if (b[i] <= a[1]) ok[1<<i-1] = 1; } 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]; } if (w[state] <= s[n]) pos[state] = lower_bound(s + 1, s + 1 + n, w[state]) - s; } for (int state = 1; state < (1<<m); state++) { // cerr << bitset<6>(state) << ": " << ok[state] << " " << w[state] << " : " << pos[state] << endl; if (ok[state] == 0) continue; if (pos[state] == n && w[state] == s[n]) { cout << "YES"; return; } for (int i = 0; i < m; i++) { if (state & (1<<i)) continue; // if ((pos[state ^ (1<<i)] == pos[state] || pos[state ^ (1<<i)] == pos[state] + 1) && w[state ^ (1<<i)] <= s[pos[state ^ (1<<i)]]) ok[state ^ (1<<i)] = 1; if (pos[state ^ (1<<i)] == pos[state]) ok[state ^ (1<<i)] = 1; else if (pos[state ^ (1<<i)] == pos[state] + 1 && w[state] == s[pos[state]]) ok[state ^ (1<<i)] = 1; } } 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...