# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732158 | Doublade | Bank (IZhO14_bank) | C++17 | 131 ms | 16760 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.
/* Author: Pieck */
#include<bits/stdc++.h>
using namespace std;
using namespace chrono;
#pragma GCC optimize("-O2")
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef vector<vector<ll>> matrix;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
for ( \
auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
blockTime.second; \
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
)
#define F first
#define S second
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rep(i,n) f(i,0,n)
#define fd(i, b, a) for(ll i=b; i>=a; i--)
#define repr(i,n) fd(i, n-1, 0)
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end()) //for set and map
#define cpresent(c,x) (find(all(c),x) != c.end()) //for vectors
#define ps(num, places) fixed<<setprecision(places)<<num //use as cout<<ps(x, y)<<"\n";
#define sz(x) (ll)(x).size()
void setIO() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
void usaco(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
template <typename T> void amax(T &a, T b) { a = max(a, b); }
template <typename T> void amin(T &a, T b) { a = min(a, b); }
const lld epsilon = 1e-9;
const ll MOD = 1e9+7;
const ll INF = 1e9;
bool comp(ll a, ll b) {
return (a > b);
}
ll POW(ll a, ll b) {
ll res = 1;
while(b>0) {
if(b&1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
ll binpow(ll a, ll b, ll p=MOD) {
ll res = 1;
a %= p;
while(b>0) {
if(b&1) (res *= a)%=p;
(a *= a)%=p;
b >>= 1;
a %= p;
res %= p;
}
return res;
}
void runcase() {
ll n, m;
cin >> n >> m;
vl a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
ll LIM = 1<<m;
vl covered(LIM, -1), leftover(LIM, -1);
// covered[i] = how many prefix salary values can be paid
covered[0] = leftover[0] = 0;
f(mask, 1, LIM) {
rep(i, m) {
if(!(mask&(1<<i))) continue;
ll prevState = mask^(1<<i);
if(covered[prevState]==-1) continue;
ll leftAmt = leftover[prevState]+b[i];
ll targetVal = a[covered[prevState]];
if(leftAmt<targetVal) {
covered[mask] = covered[prevState];
leftover[mask] = leftAmt;
}else if(leftAmt==targetVal) {
covered[mask] = 1+covered[prevState];
leftover[mask] = 0;
}
}
if(covered[mask]==n) {
cout<<"YES\n";
return;
}
}
cout<<"NO\n";
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
#ifndef ONLINE_JUDGE
// setIO();
// usaco("");
#endif
time__("Main") {
ll tests = 1;
// cin >> tests;
while(tests--) {
runcase();
}
}
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... |