# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030894 | kiethm07 | Bank (IZhO14_bank) | C++11 | 84 ms | 8644 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 pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define TEXT "a"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
const int N = 20;
int n,m;
int a[N], b[N];
int dp[1 << N], r[1 << N];
int main(){
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".out","w",stdout);
}
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
memset(dp,-1,sizeof(dp));
dp[0] = 0;
for (int mask = 0; mask < (1 << m); mask++){
for (int i = 0; i < m; i++){
if (!(mask & (1 << i))) continue;
int submask = mask ^ (1 << i);
if (dp[submask] == -1) continue;
int p = dp[submask];
int cur = r[submask] + b[i];
if (cur < a[p]){
dp[mask] = dp[submask];
r[mask] = cur;
}
if (cur == a[p]){
dp[mask] = dp[submask] + 1;
r[mask] = 0;
}
}
if (dp[mask] == n){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 0;
}
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... |