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)
bank.c: In function 'main':
bank.c:33:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
bank.c:34:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d", &M);
| ^~~~~~~~~~~~~~~
bank.c:40:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &salarios[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
bank.c:44:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &cedulas[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |