이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll
const int N = 30;
const int INF = 1e9;
int n, m, a[N], b[N];
void rec(int pos, int sum) {
if(pos == m + 1) {
if(sum == a[1]) {
cout << "YES\n";
exit(0);
}
return;
}
rec(pos + 1, sum + b[pos]);
rec(pos + 1, sum);
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fo(i, 1, n, 1) {
cin >> a[i];
}
fo(i, 1, m, 1) {
cin >> b[i];
}
if(m > 10) {
rec(1, 0);
cout << "NO\n";
return 0;
}
sort(b + 1, b + m + 1);
do {
int sum = 0, j = 1;
bool ok = 1;
fo(i, 1, m, 1) {
sum += b[i];
if(sum > a[j]) {
ok = 0;
break;
}
if(sum == a[j]) {
++j;
sum = 0;
if(j > n) break;
}
}
if(ok && sum == 0 && j == n + 1) {
cout << "YES\n";
return 0;
}
} while(next_permutation(b + 1, b + m + 1));
cout << "NO\n";
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... |