이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 21;
ll dp[(1LL<<mxn)], a[mxn], b[mxn], s_b[(1LL<<mxn)];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
ll n, m; cin >> n >> m;
for (ll i = 0; i < n; i++) {cin >> a[i]; a[i] += a[i-1];}
for (ll i = 0; i < m; i++) cin >> b[i];
for (ll i = 0; i < (1LL<<m); i++)
{
for (ll j = 0; j < m; j++) s_b[i] += b[j]*(i>>j&1);
}
dp[0] = 1;
for (ll i = 0; i < (1LL<<m); i++)
{
if (!dp[i]) continue;
ll diff = *upper_bound(a,a+n,s_b[i])-s_b[i];
for (ll j = 0; j < m; j++)
{
if (!(i>>j&1) && b[j] <= diff) dp[i^(1LL<<j)] = 1;
}
}
bool ck = 0;
for (ll i = 0; i < (1LL<<m); i++) ck |= (s_b[i] == a[n-1] && dp[i]);
if (ck) cout << "YES";
else cout << "NO";
}
# | 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... |