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;
#define ll long long
int main(){
ll n,m;
cin >> n >> m;
ll a[n],b[m];
for(int i = 0;i< n;i++)cin >> a[i];
for(int i = 0;i< m;i++)cin >> b[i];
ll dp[1<<m][2];
for(int i = 0;i< (1<<m);i++){
ll p = i;
ll k = 0;
dp[i][0] = 0;
dp[i][1] = 0;
while(p > 0){
if(p%2 == 1){
ll x = dp[i][0];
ll y = dp[i-(1<<k)][0];
ll u = dp[i][1];
ll v = dp[i-(1<<k)][1];
if(x < y+1 && v+b[k] == a[y]){
dp[i][0] = y+1;
dp[i][1] = 0;
}
if(x < y && v+b[k] < a[y]){
dp[i][0] = y;
dp[i][1] = v+b[k];
}
if(x == y && v+b[k] < a[y]){
dp[i][1] = max(v+b[k],u);
}
}
p/=2;
k++;
}
}
ll res = 0;
for(int i = 0;i <(1<<m);i++){
res = max(res,dp[i][0]);
}
if(res == n)cout << "YES" << endl;
else cout << "NO" << endl;
}
# | 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... |