제출 #996801

#제출 시각아이디문제언어결과실행 시간메모리
996801coolboy19521은행 (IZhO14_bank)C++17
100 / 100
70 ms8596 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int sm = 20; int a[sm], b[sm]; int dp[(1ll << sm)]; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; i ++) { cin >> a[i]; } for (int i = 1; i < n; i ++) { a[i] += a[i - 1]; } for (int i = 0; i < m; i ++) { cin >> b[i]; } for (int i = 0; i < (1ll << m); i ++) { int mx = -1, sm = 0; for (int j = 0; j < m; j ++) { if (i & (1ll << j)) { mx = max(mx, dp[i ^ (1ll << j)]); sm += b[j]; } } dp[i] = mx + (sm == a[mx + 1]); if (n - 1 == dp[i]) { cout << "YES"; return 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...