#include <bits/stdc++.h>
#define fr first
#define se second
#define sc scanf
#define pf printf
#define ld long double
#define ll long long
#define pb push_back
#define sq(n) n * n
#define r_0 return 0
#define pr pair < ll, ll >
#define prr pair < pair < ll, ll >, ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
const ll INF = 1e9;
const ll N = 2e3 + 3;
const ll mod = 998244353;
const ld eps = 1e-7;
ll n, m;
ll b[N], a[N];
bool dfs( ll x, ll sum, ll state, ll k, ll num ){
if( x > n ){
return 1;
}
if( sum == 0 ){
return dfs( x + 1, a[x + 1], state, 1, 0 );
}
bool mx = 0;
for( int i = k; i <= m; i ++ ){
if( sum < b[i] || ( state >> i ) & 1 == 1 || m - num < n - x )continue;
mx = max( dfs( x, sum - b[i], ( state | ( 1 << i ) ), i + 1, num + 1 ), mx );
}
return mx;
}
main(){
TIME;
//fin( "bank.in" );
//fout( "bank.out" );
cin >> n >> m;
for( int i = 1; i <= n; i ++ ){
cin >> a[i];
}
for( int i = 1; i <= m; i ++ )cin >> b[i];
ll x = dfs( 1, a[1], 0, 1, 0 );
if( x == 0 ){ cout << "NO"; }
else cout << "YES";
}
Compilation message
bank.cpp: In function 'bool dfs(long long int, long long int, long long int, long long int, long long int)':
bank.cpp:35:46: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
if( sum < b[i] || ( state >> i ) & 1 == 1 || m - num < n - x )continue;
~~^~~~
bank.cpp: At global scope:
bank.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
5 ms |
876 KB |
Output is correct |
9 |
Correct |
9 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
876 KB |
Output is correct |
2 |
Correct |
2 ms |
876 KB |
Output is correct |
3 |
Correct |
2 ms |
876 KB |
Output is correct |
4 |
Correct |
2 ms |
876 KB |
Output is correct |
5 |
Correct |
2 ms |
876 KB |
Output is correct |
6 |
Correct |
2 ms |
876 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
2 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
876 KB |
Output is correct |
2 |
Correct |
2 ms |
876 KB |
Output is correct |
3 |
Correct |
2 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
876 KB |
Output is correct |
5 |
Correct |
2 ms |
876 KB |
Output is correct |
6 |
Correct |
2 ms |
876 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
2 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
876 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
5 ms |
876 KB |
Output is correct |
9 |
Correct |
9 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
876 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
2 ms |
876 KB |
Output is correct |
13 |
Correct |
2 ms |
876 KB |
Output is correct |
14 |
Correct |
2 ms |
876 KB |
Output is correct |
15 |
Correct |
2 ms |
876 KB |
Output is correct |
16 |
Correct |
2 ms |
876 KB |
Output is correct |
17 |
Correct |
2 ms |
876 KB |
Output is correct |
18 |
Correct |
2 ms |
876 KB |
Output is correct |
19 |
Correct |
2 ms |
876 KB |
Output is correct |
20 |
Correct |
2 ms |
876 KB |
Output is correct |
21 |
Correct |
2 ms |
876 KB |
Output is correct |
22 |
Correct |
2 ms |
876 KB |
Output is correct |
23 |
Correct |
1 ms |
876 KB |
Output is correct |
24 |
Correct |
2 ms |
876 KB |
Output is correct |
25 |
Correct |
2 ms |
876 KB |
Output is correct |
26 |
Correct |
2 ms |
876 KB |
Output is correct |
27 |
Correct |
2 ms |
876 KB |
Output is correct |
28 |
Correct |
2 ms |
876 KB |
Output is correct |
29 |
Correct |
2 ms |
876 KB |
Output is correct |
30 |
Correct |
2 ms |
876 KB |
Output is correct |
31 |
Correct |
33 ms |
876 KB |
Output is correct |
32 |
Correct |
764 ms |
876 KB |
Output is correct |
33 |
Correct |
4 ms |
876 KB |
Output is correct |
34 |
Correct |
2 ms |
876 KB |
Output is correct |
35 |
Correct |
2 ms |
876 KB |
Output is correct |
36 |
Correct |
2 ms |
876 KB |
Output is correct |
37 |
Correct |
2 ms |
876 KB |
Output is correct |
38 |
Correct |
2 ms |
876 KB |
Output is correct |
39 |
Execution timed out |
1074 ms |
876 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |