Submission #1128163

#TimeUsernameProblemLanguageResultExecution timeMemory
1128163alimkhanBank (IZhO14_bank)C++20
0 / 100
1 ms580 KiB
//Bismillahir-Rahmanir-Rahim #include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ld long double #define dbg(x) cerr << #x << " = " << x << "\n"; #define ff first #define ss second /* #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma comment (linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ const long long INF = 1e9 + 7; const long long MOD = 1e9 + 7; const int maxn = 1e5 + 20; // const int lg = 20; int n, m, a[maxn], b[maxn]; pair <int, int> dp[(1 << 20)]; void press_F_() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int j = 1; j <= m; j++) { cin >> b[j]; } dp[0] = {1, 0}; for (int mask = 0; mask < (1 << m); mask++) { for (int j = 0; j < m; j++) { if (((mask >> j) & 1) == 0 && dp[mask].ff <= n && dp[mask].ss + b[j + 1] <= a[dp[mask].ff]) { int newmask = mask + (1 << j); int newid = dp[mask].ff; int sum = dp[mask].ff + b[j + 1]; if (dp[mask].ss + b[j + 1] == a[newid]) { newid++; sum = 0; } if (dp[newmask].ff <= newid) { dp[newmask] = {newid, sum}; } } } } for (int mask = 0; mask < (1 << m); mask++) { if (dp[mask].ff > n) { cout << "YES"; return; } } cout << "NO"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; // cin >> T; for (int _ = 1; _ <= T; ++_) { // cout << "Case " << i << ": "; press_F_(); } //Respa gold 2025 InshAllah // return 0; } /* Maybe not today and tomorrow, but InshAllah one day I will reach cm */ // g++ -std=c++17 main.cpp // ./a.out
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...