Cod sursa(job #1238811)

Utilizator valentinraduValentin Radu valentinradu Data 7 octombrie 2014 19:32:26
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
long n, S, a[101], i, b[7];
long compare(long a, long b)
{
    return a > b;
}

int main()
{
    f >> n >> S;
    long Sx = S;
    for (i = 1; i <= n; i++) f >> a[i];
    sort(a + 1, a + n + 1, compare);
    for (long j = 1; j <= n; j++)
    {
        long x = j;
        S = Sx;
        if (b[1] == 0 || b[2] == 0 || b[3] == 0 || b[4] == 0 || b[5] == 0 || b[6] == 0)
        {
            for (i = 1; i <= 6; i++) b[i] = 0;
            for (long i = 1; i <= 6; i++)
            {
                if (S - a[x] >= 0)
                {
                    S = S - a[x];
                    b[i] = a[x];
                }
                else
                {
                    x++;
                    i--;
                }
            }
            if (S != 0)
            {
                g << "-1";
                return 0;
            }
        }
        else
        {
            break;
        }
    }
    for (i = 1; i <= 6; i++) g << b[i] << " ";
    f.close();
    g.close();
    return 0;
}