Submission #1083871

#TimeUsernameProblemLanguageResultExecution timeMemory
1083871mmdrzadaBank (IZhO14_bank)C++17
100 / 100
86 ms10484 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define sep ' ' #define F first #define S second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define kill(x) {cout << x << endl;return;} const int N = 21; const ll LLINF = 2e18; const int INF = INT_MAX/2; int n, m; int a[N], b[N]; int dp[1<<N], remain[1<<N]; // check MAXN // diffrence between extract and erase in multi set void set_io() { fastIO; // freopen("guard.in", "r", stdin); // freopen("guard.out", "w", stdout); } void solve() { cin >> n >> m; for(int i = 0 ; i < n ; i ++) cin >> a[i]; for(int i = 0 ; i < m ; i ++) cin >> b[i]; dp[0] = 0; remain[0] = 0; for (int mask = 1 ; mask < 1<<m ; mask++) { for(int j = 0 ; j < m ; j ++) { if ((mask>>j)&1) { int x = mask ^ (1<<j); int i = dp[x]; if (remain[x] + b[j] == a[i]) { remain[mask] = 0; dp[mask] = dp[x]+1; if (dp[mask] == n) { cout << "YES" << endl; return; } i = m; } else if (dp[mask] <= dp[x]) remain[mask] = remain[x] + b[j], dp[mask] = dp[x]; } } } cout << "NO" << endl; } int main() { set_io(); 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...