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>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
#define nl endl
#define tb '\t'
#define sp ' '
#define sqr(x) (x)*(x)
#define arr3 array<ll, 3>
using namespace std;
const int MX=22, MOD=1000000007, BLOCK=160, INF=2e9+7, LG=62;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
int N, M, A[MX], B[MX], last[(1<<20)+5], coin[(1<<20)+5];
int main(){
fastio;
cin >> N >> M;
for(int i=0; i<N; i++){
cin >> A[i];
}
for(int i=0; i<M; i++){
cin >> B[i];
}
for(int mask=0; mask<(1<<M); mask++){
while(last[mask]<N && coin[mask]==A[last[mask]]){
coin[mask]-=A[last[mask]];
last[mask]++;
}
for(int i=0; i<M; i++){
if(mask&(1<<i))
continue;
int m=mask^(1<<i), c=coin[mask]+B[i], idx=last[mask];
while(idx<N && c==A[idx]){
c-=A[idx];
idx++;
}
if(last[m]<idx){
last[m]=idx;
coin[m]=c;
}else if(last[m]==idx && coin[m]<c){
last[m]=idx;
coin[m]=c;
}
}
}
if(last[(1<<M)-1]==N)
cout << "YES\n";
else
cout << "NO\n";
}
# | 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... |