Submission #475420

#TimeUsernameProblemLanguageResultExecution timeMemory
475420dpw4112001Bank (IZhO14_bank)C++14
0 / 100
115 ms262148 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main()
{

    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
    #endif
    int n;
    cin >> n;
    int m;
    cin >>m;
    int sal[n];
    int note[m];
    for(int i=0;i<n;i++)cin >> sal[i];

    for(int i=0;i<m;i++)cin >> note[i];

    vector<int> covered((1<<m)+1,-1);
    vector<int> left((1<<m)+1,-1);
    covered[0] = 0;
    left[0] = 0;
    for(int i=0;i<(1<<m);i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i & (1<<j))
            {

                int prev = i ^ (1<<j);

                if(covered[prev] == -1)
                    continue;

                int newamt = left[prev] + note[j];

                int target = sal[covered[prev]];

                if(newamt < target)
                {
                    covered[i] = covered[prev];
                    left[i] = newamt;
                }
                else if(newamt == target)
                {
                    covered[i] = covered[prev] + 1;
                    left[i] = 0;
                }
            }
        }
        if(covered[i] == n)
        {
            cout << "YES\n";
            return 0;
        }
    }

    cout << "NO";


}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:10:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |             freopen("input.txt","r",stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             freopen("output.txt","w",stdout);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...