# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887803 | Requiem | Bank (IZhO14_bank) | C++17 | 89 ms | 20712 KiB |
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>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "Bank"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = (1<<20) + 9;
int leftover[MAXN];
int dp[MAXN];
int n, m, a[MAXN], b[MAXN];
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
memset(dp,-1,sizeof(dp));
dp[0] = 0;
leftover[0] = 0;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i];
}
for(int i=1;i<(1<<m);i++){
for(int j=0;j<m;j++){
if (i & (1 << j)){
int prvmsk = i ^ (1<<j);
int prvans = dp[prvmsk];
if (leftover[prvmsk] + b[j+1] == a[prvans+1]){
dp[i] = prvans+1;
leftover[i] = 0;
}
else if (leftover[prvmsk] + b[j+1] < a[prvans+1]) {
dp[i] = prvans;
leftover[i] = leftover[prvmsk] + b[j+1];
}
}
}
if (dp[i] == n) {
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
}
Compilation message (stderr)
# | 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... |