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 <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
const int maxn = 20,inf = 1e9;
int n,m;
pii dp[1 << maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
vector<int> s(n),c(m);
for(int &i : s) cin >> i;
for(int &i : c) cin >> i;
for(int i = 0;i < (1 << m);i++)
dp[i] = {0,0};
for(int i = 1;i < (1 << m);i++)
for(int j = 0;j < m;j++)
if(i & (1 << j)){
int last = i ^ (1 << j);
pii x = dp[last];
x.second += j;
if(x.second == s[x.first]){
x.first++;
x.second = 0;
}
if(x.first == n){
cout << "YES";
return 0;
}
dp[i] = max(dp[i],x);
}
cout << "NO";
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... |