Submission #525034

#TimeUsernameProblemLanguageResultExecution timeMemory
525034Dilshod_ImomovBank (IZhO14_bank)C++17
0 / 100
1072 ms380 KiB
# include <bits/stdc++.h> # define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) # define int long long # define fi first # define se second using namespace std; const int N = 2e5 + 7; const int mod = 1e9 + 7; const int INF = 1e18 + 7; int a[N], b[N], n, m; string ans = "NO"; void rec( int i, int x, int mask ) { if ( i == n + 1 ) { ans = "YES"; return; } if ( x == 0 ) { rec( i + 1, a[i + 1], mask ); return; } for ( int j = 0; j < m; j++ ){ if ( (mask >> j) & 1 ) { if ( b[j] <= x ) { rec( i, x - b[j], mask - (1 << j) ); } } } } int32_t main() { speed; cin >> n >> m; for ( int i = 1; i <= n; i++ ) { cin >> a[i]; } for ( int i = 0; i < m; i++ ) { cin >> b[i]; } rec( 0, b[0], (1 << m)-1); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...