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>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define f first
#define s second
using namespace std;
void solve(){
int n;cin>>n;
int m;cin>>m;
int a[n+1],b[m+1];
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
int pr[n+2];pr[0]=0;
for(int i=1;i<=n;i++){
pr[i]=pr[i-1]+a[i];
}
pr[n+1]=pr[n];
int sum[(1<<m)],ind[(1<<m)],dp[(1<<m)];
for(int i=0;i<(1<<m);i++){
sum[i]=ind[i]=0;
dp[i]=0;
for(int j=0;j<m;j++){
if((1<<j)&i)sum[i]+=b[j+1];
}
int lst=0;
for(int j=1;j<=n;j++){
if(pr[j]<=sum[i])lst++;
}
ind[i]=lst;
}
dp[0]=1;
for(int i=0;i<(1<<m);i++){
for(int j=0;j<m;j++){
if(i&(1<<j)){
if(sum[i]<=pr[ind[i^(1<<j)]+1]&&dp[i^(1<<j)]){
dp[i]=1;
break;
}
}
}
}
for(int i=0;i<(1<<m);i++){
if(ind[i]==n){
if(dp[i]){
cout<<"YES\n";
return;
}
}
}
cout<<"NO\n";
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int test=1;//cin>>test;a
while(test--)solve();
}
# | 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... |