Submission #17452

#TimeUsernameProblemLanguageResultExecution timeMemory
17452azecoderBank (IZhO14_bank)C++98
71 / 100
1076 ms640 KiB
#include <iostream>

#define MAXN 21
#define intt long long

using namespace std ;

intt a[MAXN] , b[MAXN] , n , m , f ;

intt d ( intt p ) {
	
	if ( p == m ) f = 1 ;
	
	if ( f ) return 0 ;
	
	for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) {
		
		if ( f ) return 0 ;
		
		intt x = 0 ;
		
		for ( int j = 0 ; j < n ; j ++ ) {
			
			if ( ( 1 << j ) & i ) {
				
				x += a[j] ;
				
				if ( a[j] == -1 ) {
					
					x = -1 ;
					
					break ;
						
				}
				
			}
				
		}
		
		if ( x == -1 ) continue ;
		
		if ( x == b[p] ) {
			
			intt z[MAXN] ;
			
			for ( int j = 0 ; j < n ; j ++ ) {
			
				if ( ( 1 << j ) & i ) z[j] = a[j] , a[j] = -1; 
				
			}
			
			d ( p + 1 ) ;
			
			if ( f ) return 0 ;
			
			for ( int j = 0 ; j < n ; j ++ ) {
			
				if ( ( 1 << j ) & i ) a[j] = z[j] ; 
				
			}
				
		}
			
	}
	
	return 0 ;
		
}

int main () {
	
	cin >> m >> n ;
	
	for ( int i = 0 ; i < m ; i ++ ) cin >> b[i] ;
	
	for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] ;
	
	d ( 0 ) ;
	
	if ( f ) cout << "YES\n" ;
	else cout << "NO\n" ;
	
	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...