Submission #722574

#TimeUsernameProblemLanguageResultExecution timeMemory
722574PVSekharBank (IZhO14_bank)C++14
0 / 100
107 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1000000007; int main() { freopen("bank.in", "r", stdin); freopen("bank.out", "w", stdout); int n,m; cin>>n>>m; int a[n],b[m]; for (int i = 0; i < n; i++)cin>>a[i]; for (int i = 0; i < m; i++)cin>>b[i]; vector<pair<int,int>> dp((1<<m),{0,-1});// keeping 'a' fixed stores the index till which the first part of the permutaion can be used and what more is needed to pay a[index+1] dp[0].second=a[0]; bool check=false; pair<int,int> p; for (int i = 1; i < (1<<m); i++) { for (int j = 0; j < m; j++) { if(i&(1<<j)){ p=dp[i^(1<<j)]; // cout<<i<<j<<endl; if(p.second<b[j])continue; p.second-=b[j]; // cout<<i<<" "<<j<<p.first<<" "<<p.second<<endl; if(p.second==0){ p.first++; if(p.first==n){ check=true; dp[i]=p; break; } p.second=a[p.first]; } if(p.first>=dp[i].first){ dp[i]=p; } } } } if(check){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("bank.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  freopen("bank.out", "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...