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;
template<typename T>
int len(T &a){
return a.size();
}
#define ll long long
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, m; cin >> n >> m;
vector<int> people(n), mon(m);
for(auto &u : people) cin >> u;
for(auto &u : mon) cin >> u;
vector<pair<int,int>> dp(1 << m);
bool ok = 0;
for(int i = 1; i < (1 << m); i ++){
for(int j = 0; j < m; j ++){
if((i & (1 << j)) == 0) continue;
auto op = dp[i ^ (1 << j)];
if(op.ss + mon[j] < people[op.ff]){
op.ss += mon[j];
}else
if(op.ss + mon[j] == people[op.ff]){
op.ff ++; op.ss = 0;
}
dp[i] = max(dp[i], op);
}
if(dp[i].ff == n){
ok = 1; break;
}
}
cout << (ok ? "YES" : "NO");
}
# | 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... |