이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll n, m;
cin >> n >> m;
ll a[n], b[m];
for(auto &u : a)
cin >> u;
for(auto &u : b)
cin >> u;
ll M = 1 << m;
ll left[M];
ll done[M];
fur(i, 0, M - 1) {
left[i] = done[i] = -1;
}
left[0] = done[0] = 0;
fur(s, 0, M - 1) {
fur(last, 0, m - 1) {
if(!(s & (1 << last)))
continue;
ll prev = s ^ (1 << last);
if(done[prev] == -1) {
continue;
}
ll tot = left[prev] + b[last];
ll tar = a[done[prev]];
if(tot < tar) {
done[s] = done[prev];
left[s] = tot;
} else if(tot == tar) {
done[s] = done[prev] + 1;
left[s] = 0;
}
}
if(done[s] == n) {
cout << "YES" << nl;
return 0;
}
}
cout << "NO" << nl;
return 0;
}
# | 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... |