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;
#pragma GCC optimize ("Ofast,unroll-loops,trapv")
#pragma GCC target ("tune=native,avx2")
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
#define f first
#define s second
#define mkpr make_pair
#define pque priority_queue
#define pb push_back
#define pf push_front
#define vec vector
#define pf push_front
#define Yes cout << "Yes\n";
#define YES cout << "YES\n";
#define No cout << "No\n";
#define NO cout << "NO\n";
#define em(x) (bool)(x).empty()
#define all(x) (x).begin(), (x).end()
#define tc int tc;cin >> tc; while(tc--)
#define cps CLOCKS_PER_SEC
const int N = 1e5 + 5, P = 1e9 + 7;
int n, m, x, pr[N], a[N], b[N], dp[(1 << 20)];
int main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
pr[n + 1] = P;
for (int i = 0; i < m; i++)
cin >> b[i];
for (int i = 0; i < (1 << m); i++) {
x = 0;
for (int j = 0; j < m; j++)
if ((i >> j) & 1)
dp[i] = max(dp[i], dp[i ^ (1 << j)]), x += b[j];
if (pr[dp[i] + 1] == x)
dp[i]++;
}
if (dp[(1 << m) - 1] == n)
YES
else
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... |