제출 #1097281

#제출 시각아이디문제언어결과실행 시간메모리
1097281trinhbaongoc3006은행 (IZhO14_bank)C++17
0 / 100
4 ms8540 KiB
#include <bits/stdc++.h>
#define INF int64_t(1e9)
#define pii pair <int, int>
#define pll pair <long long, long long>
#define mp make_pair
#define file "test"
using namespace std;
const int nmax = 20;
const long long mod = 1e9 + 7;


int n, m, a[nmax + 2], notes[nmax + 2];

int dp[(1<<nmax)+10], g[(1<<nmax)+10];

void maximize(int &a, int b)
{
    if (a < b) a = b;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    cin >> n >> m;
    for (int i=0;i<n;i++) cin >> a[i];
    for (int i=0;i<m;i++) cin >> notes[i];

    memset(dp,-1,sizeof dp);
    memset(g,-1,sizeof dp);

    dp[0] = 0; g[0] = 0;
    for (int mask=0;mask<(1<<m);mask++)
    {
        for (int i=0;i<n;i++)
        {
            if (!(mask&(1<<i))) continue;
            int prev = mask & ~(1<<i);
            if (dp[prev] == -1) continue;
            int ok = a[i] + g[prev];
            int need = a[dp[prev]];
            if (ok < need)
            {
                dp[mask] = dp[prev];
                g[prev] += a[i];
            }
            else
            {
                dp[mask] = dp[prev] + 1;
                g[prev] = 0;
            }
        }
        if (dp[mask] == n)
        {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO";

return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...