Cod sursa(job #976561)

Utilizator j.loves_rockJessica Joanne Patrascu j.loves_rock Data 23 iulie 2013 14:18:05
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <cstdio>
#include <vector>

using namespace std;
struct rec
{
    int x,y,z;
} v;
int ind,n,i,j,a[101],s,k;
vector <rec> h[666013];
vector <rec> :: iterator it;

vector <rec> :: iterator find(int x)
{
    for(it=h[ind].begin();it!=h[ind].end();it++)
        if ((*it).x+(*it).y+(*it).z==x) return it;
    return it;
}

int main()
{
    freopen("loto.in","r",stdin);
    freopen("loto.out","w",stdout);
    scanf("%d %d",&n,&s);
    for (i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for (i=1;i<=n;i++)
    for (j=1;j<=n;j++)
    for (k=1;k<=n;k++)
    {
        if (a[i]+a[j]+a[k]*2==s) {printf("%d %d %d %d %d %d",a[i],a[i],a[j],a[j],a[k],a[k]); return 0;}
        else if (s-a[i]-a[j]-a[k]>=0)
        {
            ind=(s-a[i]-a[j]-a[k])%666013;
            it=find(s-a[i]-a[j]-a[k]);
            if(it!=h[ind].end()) {printf("%d %d %d %d %d %d", a[i],a[j],a[k],(*it).x,(*it).y,(*it).z); return 0;}
        }
        ind=(a[i]+a[j]+a[k])%666013;
        v.x=a[i];
        v.y=a[j];
        v.z=a[k];
        it=find(v.x+v.y+v.z);
        if(it==h[ind].end()) h[ind].push_back(v);
    }
    printf("-1");
    return 0;
}