Cod sursa(job #2020067)

Utilizator cyg_LucaFlorinTanasescu Luca Florin cyg_LucaFlorin Data 9 septembrie 2017 12:57:33
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.64 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct LOTO
{
    int s,x,y,z;
};

vector<LOTO>f;
vector<int>v;

int binary_search1(int x)
{
    int st,dr,med;
    st=0;
    dr=f.size()-1;
    while(st<=dr)
    {
        med=(st+dr)/2;
        if(f[med].s==x)
            return med;
        else
            if(x<v[med])
                dr=med-1;
            else
                st=med+1;
    }
    return -1;
}
int main()
{
    freopen("loto.in","r",stdin);
    freopen("loto.out","w",stdout);
    int n,s1,i,x,max1,j,d,nr;
    LOTO temp;
    scanf("%d%d",&n,&s1);
    max1=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(max1<x)
            max1=x;
        v.push_back(x);
    }
    if(max1*6<s1)
        printf("-1");
    else
    {
        for(i=0;i<v.size();i++)
        {
            temp.x=v[i];
            temp.s=temp.x;
            for(j=0;j<v.size();j++)
            {
                temp.y=v[j];
                temp.s=temp.s+temp.y;
                for(d=0;d<v.size();d++)
                    {
                        temp.z=v[d];
                        temp.s=temp.s+temp.z;
                        f.push_back(temp);
                        temp.s=temp.s-temp.z;
                    }
                temp.s=temp.s-temp.y;
            }
        }
        for(i=0;i<f.size();i++)
        {
            nr=binary_search1(s1-f[i].s);
            if(nr>-1)
            {
                printf("%d %d %d %d %d %d",f[i].x,f[i].y,f[i].z,f[nr].x,f[nr].y,f[nr].z);
                break;
            }
        }
    }
    return 0;
}