이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
const ll INF = 8e18 + 10;
const ll MOD = 1e9 + 7;
const int N = 1e5 + 10;
const int Z = 5e4 + 10;
int n, m;
int a[30], b[30], c[30];
void rec(int s[30], int ind)
{
bool t = true;
for(int i = 1; i <= n; i++)
if(s[i] != a[i])
t = false;
if(t){
cout << "YES";
exit(0);
}
if(ind == m + 1)return;
for(int i = 1; i <= n; i++)
if(s[i] + b[ind] > a[i] && s[i] != a[i])
return;
for (int i = 1; i <= n + 1; i++){
if(s[i] + b[ind] <= a[i]){
s[i] += b[ind];
rec(s, ind + 1);
s[i] -= b[ind];
}
}
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
if(n > m){
cout << "NO";
return;
}
sort(b + 1, b + m + 1);
a[n + 1] = 10000000;
rec(c, 1);
cout << "NO";
return;
}
int main()
{
int TE = 1;
ios_base::sync_with_stdio(false);
//freopen("sort.in", "r", stdin);
//freopen("sort.out", "w", stdout);
//cin >> TE;
while(TE --)
solve();
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... |