This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
vi A(1+N, 0);
for(int i = 1; i <= N; i++)
{
cin >> A[i];
A[i] += A[i-1];
}
vi b(M, 0);
for(int j = 0; j < M; j++)
cin >> b[j];
vi s((1<<M), 0);
for(int j = 0; j < M; j++)
for(int m = 0; m < (1<<M); m++)
if(m & (1 << j))
s[m] += b[j];
vi dp((1<<M), 0);
dp[0] = 1;
for(int m = 0; m < (1<<M); m++)
{
if(!dp[m]) continue;
int i = 0;
while(i+1 <= N && A[i+1] <= s[m])
i++;
if(i == N)
{
cout << "YES\n";
return 0;
}
for(int z = 0; z < M; z++)
{
if(m & (1<<z)) continue;
if(s[m] + b[z] <= A[i+1])
dp[m | (1 << z)] = 1;
}
}
cout << "NO\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |