This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 25
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long
using namespace std;
typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;
int n, m;
int pp[N], s[N];
void readfile()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(Task".inp","r"))
{
freopen(Task".inp","r",stdin);
//freopen(Task".out","w",stdout);
}
cin >> n >> m;
for(int i=0; i<n; i++) cin >> pp[i];
for(int i=0; i<m; i++) cin >> s[i];
}
int dp[1<<20];
int lef[1<<20];
void proc()
{
memset(dp, -1, sizeof dp);
memset(lef, -1, sizeof lef);
dp[0] = 0;
lef[0] = 0;
int mm = 1<<m;
for(int msk = 0; msk < mm; msk++){
for(int i=0; i<m; i++){
if (msk&(1<<i)){
int pre = msk^(1<<i);
if (dp[pre]==-1) continue;
int new_atm = lef[pre]+s[i];
int cur_tar = pp[dp[pre]];
if (new_atm < cur_tar){
lef[msk] = new_atm;
dp[msk] = dp[pre];
}
else if (new_atm == cur_tar){
dp[msk] = dp[pre]+1;
lef[msk] = 0;
}
}
}
if (dp[msk]==n){
cout << "YES";
return;
}
}
cout << "NO";
}
signed main()
{
readfile();
proc();
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void readfile()':
bank.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen(Task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |