Submission #37402

#TimeUsernameProblemLanguageResultExecution timeMemory
37402HardNutBank (IZhO14_bank)C++14
71 / 100
1081 ms760 KiB
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N = 1e5 + 5; typedef long long ll; int n, m, a[25], b[25]; bool used[25]; void rec(int v, int sum, int cur) { if (a[v] == sum) { v++; if (v == n + 1) { cout << "YES"; exit(0); } sum = 0; cur = 0; } for (int i = cur + 1; i <= m; i++) { if (!used[i] && sum + b[i] <= a[v]) { used[i] = 1; rec(v, sum + b[i], i); used[i] = 0; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; } rec(1, 0, 0); cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...