이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define ft first
#define sd second
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vll;
#define dgb if(0)
const ll MOD = 1e18;
const int INF = 1e9;
int n, m;
void solve(){
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];
int covered[1<<m]{}, leftover[1<<m]{};
bool ans = false;
for (int i = 1;i<(1<<m);i++){
for (int j = 0;j<m;j++){
if (i&(1<<j)){
int pre = i^(1<<j);
if (leftover[pre]+b[j]==a[covered[pre]]) {
covered[i] = covered[pre]+1;
ans|=(covered[i]==n);
leftover[i] = 0;
}
else if (leftover[pre]+b[j]<a[covered[pre]]) {
covered[i] = covered[pre];
leftover[i] = leftover[pre]+b[j];
}
}
}
}
if (ans) cout<<"YES";
else cout<<"NO";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("movie.in", "r", stdin);
// freopen("movie.out", "w", stdout);
int t=1;
// cin>>t;
while(t--){
solve();
cout<<'\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... |