#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
#define seea(a , x , y) for(int i = x; i < y; i++){cin >> a[i];}
#define sees(s , n) for(int i = 0;i < n; i++){int x; cin >> x; s.insert(x);}
#define seev(v , n) for(int i = 0;i < n; i++){int x; cin >> x; v.push_back(x);}
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pii pair<int , int>
#define sz(x) (int)x.size()
#define pq priority_queue
#define int long long
#define vec vector
#define arr array
const int inf = 1e18, N = 4e5 + 5;
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void solve() {
// Code here
int n , m;
see(n , m);
vec<int> a , b;
seev(a , n); seev(b, m );
vec<int> dp(1 << m , -1) , cp(1 << m , -1);
dp[0] = cp[0] = 0;
for (int mask = 0; mask < (1 << m); mask++){
for (int i = 0; i < m; i++){
if (mask & (1 << i)){
int fr = mask & ~(1 << i);
if (cp[fr] != -1){
int x = dp[fr] + b[i];
int y = a[cp[fr]];
if (x < y)
cp[mask] = cp[fr],
dp[mask] = x;
else if (x == y)
cp[mask] = cp[fr] + 1,
dp[mask] = 0;
}
}
}
if (cp[mask] == n)
return cout << "YES\n" , void();
}
cout << "NO\n";
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// setIO("");
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void setIO(std::string)':
bank.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |