# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
5027 | ainta | Bank (IZhO14_bank) | C++98 | 180 ms | 560 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n, m, a[20], b[20], o[1010];
bool v[20];
bool DFS(int x, int C);
bool Do(int x, int S, int p, int C, int cnt){
int i;
if (!S){
if (DFS(x + 1, C - cnt))return true;
return false;
}
if (cnt == C - (n - x) * 2 + 2)return false;
for (i = p; i < m; i++){
if (!v[i] && S >= b[i]){
v[i] = true;
if (Do(x, S - b[i], i + 1, C, cnt + 1))return true;
v[i] = false;
}
}
return false;
}
bool DFS(int x, int C){
if (x == n){
return true;
}
if ((n - x) * 2 > C)return false;
return Do(x, a[x], 0, C, 0);
}
int main(){
int i, j;
scanf("%d%d", &n, &m);
int t;
for (i = 0; i < n; i++){
scanf("%d", &t);
o[t]++;
}
for (i = 0; i < m; i++){
scanf("%d", &t);
o[t]--;
}
n = 0, m = 0;
for (i = 1; i <= 1000; i++){
if (o[i]){
while (o[i] > 0)a[n++] = i, o[i]--;
while (o[i] < 0)b[m++] = i, o[i]++;
}
}
printf(DFS(0, m)?"YES" : "NO");
}
Compilation message (stderr)
# | 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... |