Submission #366709

#TimeUsernameProblemLanguageResultExecution timeMemory
366709Sparky_09Bank (IZhO14_bank)C++17
100 / 100
161 ms632 KiB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

int rd(){
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

int N,M;
bitset<1<<20> dp;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  N = rd();
  M = rd();
  vi cum{0};
  vi a(N), b(M); trav(x,a) x=rd(); 
  trav(x,b) x=rd();
  trav(t,a) cum.push_back(cum.back()+t);
  dp[0]=1;
  rep(i,0,1<<M) { 
  	if (dp[i]) {
      int sum = 0;
      rep(j,0,M) if (i&(1<<j)) sum += b[j];
      int ind = 0; while (ind+1 < sz(cum) && cum[ind+1] <= sum) ++ind;
      if (ind == sz(cum)-1) {
        cout << "YES";
        return 0;
      }
      rep(j,0,M) if (!(i&(1<<j))) {
        if (sum+b[j] <= cum[ind+1]) {
          dp[i^(1<<j)] = 1;
        }
      }
    }
 }
 cout << "NO";
}
  


Compilation message (stderr)

bank.cpp: In function 'void usaco(std::string)':
bank.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   freopen((s+".out").c_str(), "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...