#include<bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,m,a[205],b[205];
ll sum[3000005],ind[3000005],dp[3000005];
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i];
a[i] += a[i - 1];
}
a[n + 1] = a[n];
for(int i=1; i<=m; i++){
cin >> b[i];
}
sum[0] = 0;
for(int i=1; i<=m; i++)
for(int j=0; j<(1 << m); j++)
if((j & (1 << (i - 1))) == 0)
sum[j | (1 << (i - 1))] = sum[j] + b[i];
dp[0] = 1;
for(int j=0; j<(1 << m); j++){
ll lst = 0;
for(int i=1; i<=n; i++)
if(a[i] <= sum[j])
lst = i;
ind[j] = lst;
}
for(int j=1; j<(1 << m); j++)
for(int i=1; i<=m; i++)
if(j & (1 << (i - 1)))
if(sum[j] <= a[ind[j - (1 << (i - 1))] + 1] && dp[j - (1 << (i - 1))])
dp[j] = 1;
for(int i=0; i<(1 << m); i++)
if(ind[i] == n && dp[i]){
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
760 KB |
Output is correct |
5 |
Correct |
120 ms |
8696 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
123 ms |
12700 KB |
Output is correct |
9 |
Correct |
129 ms |
12664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
760 KB |
Output is correct |
5 |
Correct |
120 ms |
8696 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
123 ms |
12700 KB |
Output is correct |
9 |
Correct |
129 ms |
12664 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
504 KB |
Output is correct |
21 |
Correct |
4 ms |
632 KB |
Output is correct |
22 |
Correct |
4 ms |
504 KB |
Output is correct |
23 |
Correct |
4 ms |
504 KB |
Output is correct |
24 |
Correct |
4 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
142 ms |
12708 KB |
Output is correct |
32 |
Correct |
142 ms |
12696 KB |
Output is correct |
33 |
Correct |
169 ms |
12500 KB |
Output is correct |
34 |
Correct |
162 ms |
9720 KB |
Output is correct |
35 |
Correct |
161 ms |
9724 KB |
Output is correct |
36 |
Correct |
176 ms |
8792 KB |
Output is correct |
37 |
Correct |
121 ms |
9068 KB |
Output is correct |
38 |
Correct |
123 ms |
8568 KB |
Output is correct |
39 |
Correct |
130 ms |
12664 KB |
Output is correct |
40 |
Correct |
145 ms |
8696 KB |
Output is correct |
41 |
Correct |
172 ms |
8796 KB |
Output is correct |
42 |
Correct |
172 ms |
12664 KB |
Output is correct |
43 |
Correct |
165 ms |
11336 KB |
Output is correct |
44 |
Correct |
157 ms |
8756 KB |
Output is correct |
45 |
Correct |
159 ms |
12636 KB |
Output is correct |
46 |
Correct |
172 ms |
12664 KB |
Output is correct |
47 |
Correct |
152 ms |
8824 KB |
Output is correct |
48 |
Correct |
123 ms |
12536 KB |
Output is correct |
49 |
Correct |
121 ms |
8740 KB |
Output is correct |
50 |
Correct |
147 ms |
12644 KB |
Output is correct |
51 |
Correct |
140 ms |
8960 KB |
Output is correct |
52 |
Correct |
154 ms |
12664 KB |
Output is correct |
53 |
Correct |
147 ms |
12792 KB |
Output is correct |
54 |
Correct |
150 ms |
12664 KB |
Output is correct |
55 |
Correct |
147 ms |
12664 KB |
Output is correct |
56 |
Correct |
148 ms |
12664 KB |
Output is correct |
57 |
Correct |
159 ms |
12768 KB |
Output is correct |
58 |
Correct |
148 ms |
12636 KB |
Output is correct |