Cod sursa(job #1387056)

Utilizator AndreiITCuriman Andrei AndreiIT Data 13 martie 2015 17:44:51
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define MOD 666013
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int n, s, a[105], np;
struct loto{
    int s, a, b, c;
    loto()
    {
        s = a = b = c = 0;
    }
    loto (int ss, int aa, int bb, int cc)
    {
        s = ss;
        a = aa;
        b = bb;
        c = cc;
    }
};
loto v[1000000];
vector <loto> H[MOD];

int main()
{
    fin>>n>>s;
    for(int i=1;i<=n;++i)
        fin>>a[i];
    fin.close();
    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
            for(int k=j;k<=n;++k)
                {
                    int cod = (a[i] + a[j] + a[k]) % MOD;
                    H[cod].push_back(loto(a[i]+a[j]+a[k], a[i], a[j], a[k]));
                    v[++np] = loto(a[i]+a[j]+a[k], a[i], a[j], a[k]);

                }
    for(int i=1;i<=np;i++)
    {
        int x = s - v[i].s;
        if (x < 0)
            continue;
        int cod = x % MOD;
        int lg = H[cod].size();
        for (int j = 0; j < lg; ++ j)
        {
            if (H[cod][j].s == x)
            {
                fout << v[i].a << " " << v[i].b << " " << v[i].c << " " << H[cod][j].a << ' ' << H[cod][j].b << " " << H[cod][j].c << "\n";
                fout.close();
                return 0;
            }
        }

    }
    fout<<"-1\n";
    fout.close();
    return 0;
}