# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073085 | vjudge1 | 은행 (IZhO14_bank) | C++17 | 2 ms | 348 KiB |
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
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
const ll MOD=1000000007;
bool dp[20][(1<<20)];
void solve(){
int n,m;
cin>>n>>m;
int a[n],pr[n],b[m];
for(int i=0; i<n; i++){
cin>>a[i];
if(i==0) pr[i]=a[i];
else pr[i]=pr[i-1]+a[i];
}
for(int i=0; i<m; i++) cin>>b[i];
sort(b,b+m);
vector<int>ans;
ans.pb(0);
for(int i=0; i<n; i++){
vector<int>cur;
for(int j=1; j<(1<<m); j++){
int sum=0;
for(int k=0; k<m; k++) if((1<<k)&j) sum+=b[k];
if(sum>pr[i]) break;
if(sum==pr[i]){
if(i==0) cur.pb(j);
else for(int k=0; k<ans.size(); k++) if(ans[k]&j==ans[k]) cur.pb(j);
}
}
ans=cur;
}
if(ans.size()>0) cout<<"YES";
else cout<<"NO";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
for(int _=0; _<t; _++){
// cout<<"Case "<<_+1<<":\n";
solve();
}
return 0;
}
//080129552180
Compilation message (stderr)
# | 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... |