#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define repp(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define eb emplace_back
#define pb push_back
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define rtn return
#define trav(it,v) for(auto&it:(v))
#define rsz resize
#define tcT template<class T
#define tcTU tcT,class U
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pii> vpii;
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b) - begin(a)); }
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { // assert(x >= 0);
return x == 0 ? 0 : 31-__builtin_clz(x); }
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; }
tcT> bool ckmax(T& a, const T& b) {
return b > a ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }
tcTU> T fstTrue(T lo ,T hi, U f) {
hi++ ; assert(lo <= hi);
while(lo < hi) {
T mid = lo + (hi - lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
lo--; assert(lo <= hi);
while(lo < hi) {
T mid = lo + (hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)),end(v)); }
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void setPrec() { cout << fixed << setprecision(16); }
void setIO(str name = "") {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
setPrec();
if(sz(name)) {
freopen((name + ".in").c_str(),"r",stdin);
freopen((name + ".out").c_str(),"w",stdout);
}
}
const int MASK = 1<<21;
struct dya {
int cvr=-1, lf=-1, prev_mask=-1, pson=-1;
} dp[MASK];
int N,M;
int sal[25],note[25];
void solve() {
cin>>N>>M;
F0R(i,N) cin>>sal[i];
F0R(i,M) cin>>note[i];
dp[0].cvr=dp[0].lf=0;
F0R(mask,1<<M) {
F0R(lst,M) {
if(mask>>lst&1) {
int prvmsk = mask&~(1<<lst);
if(~dp[prvmsk].cvr) {
int have = dp[prvmsk].lf+note[lst];
if(have<sal[dp[prvmsk].cvr]) {
dp[mask]=dp[prvmsk];
dp[mask].lf=have;
dp[mask].prev_mask=prvmsk;
}
else if(have==sal[dp[prvmsk].cvr]) {
dp[mask].cvr=dp[prvmsk].cvr+1;
dp[mask].lf=0;
dp[mask].prev_mask=prvmsk;
dp[mask].pson=dp[prvmsk].cvr;
}
}
}
}
if(dp[mask].cvr==N) return void(cout<<"YES\n");
}
cout << "NO\n";
}
//#define TC
int main() {
setIO();
int t=1;
#ifdef TC
cin>>t;
#endif
while(t-- > 0) {
solve();
}
return 0;
}
Compilation message
bank.cpp: In function 'void setIO(str)':
bank.cpp:122:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
122 | freopen((name + ".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:123:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | freopen((name + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
82 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
86 ms |
16668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
82 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
86 ms |
16668 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
108 ms |
16708 KB |
Output is correct |
32 |
Correct |
110 ms |
16660 KB |
Output is correct |
33 |
Correct |
93 ms |
13664 KB |
Output is correct |
34 |
Correct |
76 ms |
2244 KB |
Output is correct |
35 |
Correct |
80 ms |
2236 KB |
Output is correct |
36 |
Correct |
74 ms |
568 KB |
Output is correct |
37 |
Correct |
76 ms |
836 KB |
Output is correct |
38 |
Correct |
81 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
332 KB |
Output is correct |
40 |
Correct |
76 ms |
332 KB |
Output is correct |
41 |
Correct |
76 ms |
452 KB |
Output is correct |
42 |
Correct |
139 ms |
16612 KB |
Output is correct |
43 |
Correct |
80 ms |
6084 KB |
Output is correct |
44 |
Correct |
76 ms |
356 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
113 ms |
16040 KB |
Output is correct |
47 |
Correct |
77 ms |
564 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
82 ms |
452 KB |
Output is correct |
50 |
Correct |
114 ms |
16708 KB |
Output is correct |
51 |
Correct |
79 ms |
1272 KB |
Output is correct |
52 |
Correct |
89 ms |
16060 KB |
Output is correct |
53 |
Correct |
124 ms |
16632 KB |
Output is correct |
54 |
Correct |
115 ms |
16628 KB |
Output is correct |
55 |
Correct |
108 ms |
16708 KB |
Output is correct |
56 |
Correct |
97 ms |
16708 KB |
Output is correct |
57 |
Correct |
110 ms |
16692 KB |
Output is correct |
58 |
Correct |
96 ms |
16708 KB |
Output is correct |