Cod sursa(job #1780664)

Utilizator nedelcu11Nedelcu Mihai Vlad nedelcu11 Data 16 octombrie 2016 14:47:35
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include<fstream>
#include<vector>
#define NMAX 110
#define MOD 666013
using namespace std;
ifstream f("loto.in"); ofstream g("loto.out");
int a[NMAX], n, S;
struct art {int s, a, b, c;} r;
vector <art> h[MOD+100];
int main()
{   f>>n>>S;
    for(int i=1; i<=n; ++i) f>>a[i];
    int y, x; bool w=true;
    for (int i=1; i<=n && w; ++i)
        for (int j=i; j<=n && w; ++j)
            for (int k=j; k<=n && w; ++k)
                if(a[i]+a[j]+a[k]<=S)
                {   r.s=a[i]+a[j]+a[k]; r.a=a[i]; r.b=a[j]; r.c=a[k];
                    x=r.s%MOD; h[x].push_back(r);
                    x=S-r.s; y=x%MOD;
                    vector <art> :: iterator it=h[y].begin(), sf=h[y].end();
                    for(; it != sf; ++it)
                        if((*it).s==x)
                        {
                            g<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<(*it).a;
                            g<<" "<<(*it).b<<" "<<(*it).c<<"\n";
                            w=false;
                        }
                }
    if (w) g<<"-1\n";
    g.close(); return 0;
}