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 int long long
#define printmp(a) for(auto x : a) cout << x.first << ' ' << x.second << endl;
signed main(){
int n, m;
cin >> n >> m;
vector<int> b(n);
for (int i = 0; i < n; i++)
cin >> b[i]; // debt
vector<int> a(m);
for(int i = 0; i < m; i ++)
cin >> a[i]; // tenges
vector<pair<int, int>> dp((1 << m) + 1);
for(int i = 0; i <= (1 << m); i ++){
pair<int, int> best = {0, 0};
for(int j = 0; j < m; j ++){
if((i & (1 << j)) == (1 << j)){
if(b[dp[i ^ (1 << j)].first] - dp[i ^ (1 << j)].second > a[j])
best = max(best, {dp[i ^ (1 << j)].first, dp[i ^ (1 << j)].second + a[j]});
if (b[dp[i ^ (1 << j)].first] - dp[i ^ (1 << j)].second == a[j])
best = max(best, {dp[i ^ (1 << j)].first + 1, 0});
}
}
if(best.first == n){
cout << "YES";
return 0;
}
dp[i] = best;
}
cout << "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... |