#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()
{
fin >> n >> m;
for(int i = 1; i <= n; i++)
fin >> s[i];
for(int i = 0; i < m; i++){
fin >> 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){
fout << "YES\n";
return 0;
}
}
else if(s[lastppl] > moneyDisp){
dp[(stare | (1 << j))] = {dp[stare].first, moneyDisp};
}
}
}
fout << "NO\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |