Cod sursa(job #1245578)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 19 octombrie 2014 15:28:00
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");

const int nmax = 106;
int n, s, v[nmax], nr[nmax * nmax * nmax], lung;

int main(){
	int player_unu=0;

	in>>n>>s;
    for(int i = 0; i<n; i++)
        in>>v[i];

    for(int i = 0; i<n; i++)
        for(int j = i; j<n; j++)
            for(int k = j; k<n; k++)
			{
				nr[lung] = v[i] + v[j] + v[k];
				lung++;
			}

    sort(nr, nr + lung);

    for(int i = 0; i<n; i++)
        for(int j = i; j<n; j++)
            for(int k = j; k<n; k++)
			{
                int poz = 0;
                for (int chestie = 1<<19; chestie; chestie/=2)
                    if (poz + chestie<lung && nr[poz + chestie]<=s - v[i] - v[j] - v[k])
						poz += chestie;

                if (nr[poz]!=s - v[i] - v[j] - v[k]) 
					continue;

                for (int p1 = 0; p1<n; p1++)
                    for (int p2 = p1; p2<n; p2++)
                        for (int p3 = p2; p3<n; p3++)
                            if (v[p1] + v[p2] + v[p3] == nr[poz])
							{
                                out<<v[i]<<' '<<v[j]<<' '<<v[k]<<' '<<v[p1]<<' '<<v[p2]<<' '<<v[p3]<<'\n';
                                return 0;
							}
            }

	out<<-1<<'\n';
	return player_unu;
}