Submission #870841

#TimeUsernameProblemLanguageResultExecution timeMemory
870841ljlkjBank (IZhO14_bank)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n , m;
    cin >> n >> m;
    vector<int> persons(n);
    vector<int> notes(m);
    for(int i = 0; i < n; i++) cin >> persons[i];
    for(int i = 0; i < m; i++) cin >> notes[i];
    
    vector<pair<int , int>> dp(1<<m);
    for(int s = 0; s < (1<<m); s++){
        dp[s].first = -1;
        dp[s].second = 0;
        for(int b = 0; b < n; b++){
             if(s&&(1<<b)){
                int lastIndex = dp[s^(1<<b)].first;
                int value = dp[s^(1<<b)].second;
                if(notes[b] + value == persons[lastIndex]){
                    if(dp[s].first < lastIndex + 1){
                        dp[s].first = lastIndex + 1;
                        dp[s].second = 0;
                    }
                }
                else if(notes[b] + value < persons[lastIndex]){
                    if(dp[s].first < lastIndex){
                        dp[s].first = lastIndex;
                        dp[s].second = value + notes[b];
                    }
                }

             }
        }

    }

    // cout << "test: " << dp[(1<<m) - 1].first << endl;

    if(dp[(1<<m) - 1].first == n) cout << "YES";
    else cout << "NO";


    return 0;
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:17:22: warning: '<<' in boolean context, did you mean '<'? [-Wint-in-bool-context]
   17 |              if(s&&(1<<b)){
      |                    ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...