Cod sursa(job #202318)

Utilizator piroslPiros Lucian pirosl Data 7 august 2008 13:14:56
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int numere[101];

int main(void)
{
	int n, s;
	vector<int> valori;
	freopen("loto.in", "r", stdin);
	freopen("loto.out", "w", stdout);
	cin >> n >> s;
	for(int i = 0;i<n;++i)
		cin >> numere[i];
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			for(int k=0;k<n;++k)
			{
				valori.push_back(numere[i] + numere[j] + numere[k]);
			}
		}
	}

	sort(valori.begin(), valori.end());
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			for(int k=0;k<n;++k)
			{
				int tmpS = s - (numere[i] + numere[j] + numere[k]);
				if(binary_search(valori.begin(), valori.end(), tmpS))
				{
					for(int i1=0;i1<n;++i1)
					{
						for(int j1=0;j1<n;++j1)
						{
							for(int k1=0;k1<n;++k1)
							{
								if(tmpS == numere[i1] + numere[j1] + numere[k1])
								{
									cout << numere[i] << " " << numere[j] << " " << numere[k] << " " <<  numere[i1] << " " << numere[j1] << " " << numere[k1] << endl;
									return 0;
								}
							}
						}
					}
				}
			}
		}
	}
	cout << -1 << endl;
	return 0;
}