# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
366709 | Sparky_09 | Bank (IZhO14_bank) | C++17 | 161 ms | 632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |