Submission #777091

#TimeUsernameProblemLanguageResultExecution timeMemory
777091Halym2007Bank (IZhO14_bank)C++11
100 / 100
148 ms1380 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define sz size() #define pb push_back using namespace std; typedef long long ll; const int N = 21; // const int mod = 1e9+7; // ll bigmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} void solve(); int n, m, a[N], b[N], p[N], sum; bool dp[1 << N]; int main() { // ios::sync_with_stdio(false); // cin.tie(0), cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // clock_t tStart = clock(); // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; p[i] = p[i - 1] + a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } dp[0] = 1; for (int i = 0; i < (1 << m); ++i) { // cout << "1" << endl; sum = 0; for (int j = 0; j < m; ++j) { // cout << "2" << endl; if (i>>j&1) { sum += b[j]; } } auto pos = lower_bound (p + 1, p + n + 1, sum) - p; if (pos == n + 1) { continue; } for (int j = 0; j < m; ++j) { // cout << "3" << endl; if ((i>>j&1) and (b[j] <= sum - p[pos - 1])) dp[i] |= dp[i ^ (1 << j)]; } if ((p[n] == sum) and (dp[i])) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; } /* ██╗░░██╗░█████╗░██╗░░░░░██╗░░░██╗███╗░░░███╗██████╗░░█████╗░░█████╗░███████╗ ██║░░██║██╔══██╗██║░░░░░╚██╗░██╔╝████╗░████║╚════██╗██╔══██╗██╔══██╗╚════██║ ███████║███████║██║░░░░░░╚████╔╝░██╔████╔██║░░███╔═╝██║░░██║██║░░██║░░░░██╔╝ ██╔══██║██╔══██║██║░░░░░░░╚██╔╝░░██║╚██╔╝██║██╔══╝░░██║░░██║██║░░██║░░░██╔╝░ ██║░░██║██║░░██║███████╗░░░██║░░░██║░╚═╝░██║███████╗╚█████╔╝╚█████╔╝░░██╔╝░░ ╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝░░░╚═╝░░░╚═╝░░░░░╚═╝╚══════╝░╚════╝░░╚════╝░░░╚═╝░░░ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...