Submission #1138370

#TimeUsernameProblemLanguageResultExecution timeMemory
1138370AgageldiBank (IZhO14_bank)C++20
19 / 100
1094 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 600005 #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() ll T, n, a[N], t, m, b[N], pos[N], vis[N]; void solve(int x) { if(x == n + 1) { cout << "YES\n"; exit(0); } for(int j = 1; j <= a[x]; j++) { pos[j] = 0; } pos[0] = 1; for(int j = 1; j <= m; j++) { if(vis[j]) continue; for(int k = 1000; k >= 0; k--) { if(pos[k] != 0 && pos[k + b[j]] == 0) { pos[k + b[j]] = j; } } } if(!pos[a[x]]) return; int tt = a[x]; while(tt > 0) { vis[pos[tt]] = 1; tt -= b[pos[tt]]; } solve(x + 1); tt = a[x]; while(tt > 0) { vis[pos[tt]] = 0; tt -= b[pos[tt]]; } } int main () { cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 1; i <= m; i++) { cin >> b[i]; } solve(1); cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...