# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
554569 | rafatoa | Bank (IZhO14_bank) | C++17 | 106 ms | 97648 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>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define int ll
#define double ld
const int inf = 2e9;
const int INF = 4e18;
const int mod = 1e9+7;
const int mx = 200001;
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define ppb pop_back
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n, m; cin >> n >> m;
vi a(n), b(m); read(a); read(b);
vpi best(1<<m, {0, 0});
for(int s=1; s<(1<<m); s++){
for(int t=0; t<m; t++){
pi option = best[s^(1<<t)];
if(best[s^(1<<t)].S + b[t] < a[best[s^(1<<t)].F]){
option.S = best[s^(1<<t)].S + b[t];
} else if(best[s^(1<<t)].S + b[t] == a[best[s^(1<<t)].F]){
option.F++;
option.S = 0;
}
best[s] = max(best[s], option);
}
}
for(auto x:best){
if(x.F == n && x.S == 0){
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... |