Cod sursa(job #1238692)

Utilizator valentinraduValentin Radu valentinradu Data 7 octombrie 2014 15:40:25
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int n, S, a[101], i, b[6];
int compare(int a, int b)
{
    return a > b;
}
void alg(int l, int x, int k)
{
    if (x - a[l] < 0 || k > 5)
    {
        b[k - 1] = 0;
        return;
    }
    if (x - a[l] != 0 && x - a[l] < a[l])
    {
        alg(l + 1, x - a[l], k + 1);
        b[k] = a[l];
    }
    else
    {
        alg(l, x - a[l], k + 1);
        b[k] = a[l];
    }

}
int main()
{
    f >> n >> S;
    for (i = 1; i <= n; i++) f >> a[i];
    sort(a + 1, a + n + 1, compare);
    alg(1, S, 0);
    for (i = 0; i < 6; i++) g << b[i] << " ";
    f.close();
    g.close();
    return 0;
}