# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088557 | vjudge1 | Bank (IZhO14_bank) | C11 | 3 ms | 424 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.
#include <stdio.h>
#include <stdbool.h>
void ordena(int v[], int tam) {
for(int i = 0; i < tam - 1; i++) {
int min = i;
for(int j = i + 1; j < tam; j++) {
if(v[j] > v[min]) {
min = j;
}
}
if(i != min) {
int aux = v[i];
v[i] = v[min];
v[min] = aux;
}
}
}
// Função recursiva para verificar se podemos formar um salário exato com as cédulas disponíveis
bool pode_formar(int salario, int cedulas[], int m) {
if (salario == 0)
return true;
if (salario < 0 || m == 0)
return false;
// Tenta formar o salário incluindo ou não a última cédula
return pode_formar(salario - cedulas[m - 1], cedulas, m - 1) || pode_formar(salario, cedulas, m - 1);
}
int main() {
int N, M;
scanf("%d", &N);
scanf("%d", &M);
int salarios[N];
int cedulas[M];
for(int i = 0; i < N; i++) {
scanf("%d", &salarios[i]);
}
for(int i = 0; i < M; i++) {
scanf("%d", &cedulas[i]);
}
// Ordena os salários e as cédulas em ordem decrescente
ordena(salarios, N);
ordena(cedulas, M);
bool possivel = true;
for(int i = 0; i < N; i++) {
if (!pode_formar(salarios[i], cedulas, M)) {
possivel = false;
break;
}
}
if (possivel) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
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... |