이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, 1e9};
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 |
---|
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... |