Cod sursa(job #1419129)

Utilizator crysstyanIacob Paul Cristian crysstyan Data 14 aprilie 2015 19:06:52
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define NMAX 101

using namespace std;

ifstream f("loto.in");
ofstream g("loto.out");

int i, j, k, n, s, nr, x[NMAX];

struct loto
{
    int unu, doi, trei, val;
};

loto v[NMAX*NMAX*NMAX];

bool cmp(loto a, loto b)
{
    return a.val<b.val;
}

int cautbin(int st, int dr, int x)
{
    int med;

    while (st<=dr)
    {
        med=(st+dr)/2;
        if (v[med].val==x) return med;
        else
            if (x<v[med].val) dr=med-1;
        else
            if (x>v[med].val) st=med+1;
    }
    return -1;
}

int main()
{
    f>>n>>s;

    for (i=1; i<=n; ++i)
    f>>x[i];

    int cont=0;

    for (i=1; i<=n; ++i)
        for (j=1; j<=n; ++j)
        for (k=1; k<=n; ++k)
        {
            cont++;
            v[cont].val=x[i]+x[j]+x[k];
            v[cont].unu=x[i];
            v[cont].doi=x[j];
            v[cont].trei=x[k];
        }

    sort(v+1, v+cont+1, cmp);

    bool gasit=0;

    for (i=1; i<=cont; ++i)
    {
      //  int x=cautbin(i,cont,s-v[i].val);
      int x=1;
        if (x!=-1)
        {
            g<<v[i].unu<<" "<<v[i].doi<<" "<<v[i].trei<<" "<<v[x].unu<<" "<<v[x].doi<<" "<<v[x].trei<<'\n';
            gasit=1;
            return 0;
        }
    }

    if (!gasit) g<<"-1\n";

    return 0;
}