제출 #776910

#제출 시각아이디문제언어결과실행 시간메모리
776910Halym2007은행 (IZhO14_bank)C++11
25 / 100
1087 ms320 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 = 25; // 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]; 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]; } for (int i = 1; i <= m; ++i) { cin >> b[i]; } sort (b + 1, b + m + 1); do { int pos = 1; int sum = 0; int bolonok = 0; for (int i = 1; i <= m; ++i) { if (pos == n + 1) break; if (sum < a[pos]) { sum += b[i]; } else if (sum > a[pos]) { bolonok = 1; break; } else { if (pos == n) break; pos++; sum = 0; sum += b[i]; } } if (pos <= n) { if (sum == a[pos]) pos++; } if (bolonok or pos != (n + 1)) { continue; } return cout << "YES\n", 0; }while (next_permutation(b + 1, b + m + 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...