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;
ifstream fin("bank.in");
ofstream fout("bank.out");
int n, m, s[1005], b[1005];
pair<int, int>dp[(1 << 20) + 10];
///in dp[stare] retin ultima persoana pe care am platit o cu bancnotele din stare si suma de bani ramasa dupa ce i am platit, care trebuie sa fie fixa pt a-l plati pe urmatorul
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> s[i];
for(int i = 0; i < m; i++){
cin >> b[i];
}
for(int i = 0; i < (1 << m); i++)
dp[i] = {-1, 0};
dp[0] = {0, 0};
for(int stare = 0; stare < (1 << m); stare++)
for(int j = 0; j < m; j++){
if(!(stare & (1 << j)) && dp[stare].first != -1){
int moneyDisp = dp[stare].second + b[j];
int lastppl = dp[stare].first + 1;
if(s[lastppl] == moneyDisp){
dp[(stare | (1 << j))].first = lastppl;
dp[(stare | (1 << j))].second = moneyDisp - s[lastppl];
if(lastppl == n){
cout << "YES\n";
return 0;
}
}
else if(s[lastppl] > moneyDisp){
dp[(stare | (1 << j))] = {dp[stare].first, moneyDisp};
}
}
}
cout << "NO\n";
return 0;
}
# | 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... |