Cod sursa(job #130507)

Utilizator scvalexAlexandru Scvortov scvalex Data 1 februarie 2008 13:15:06
Problema Loto Scor 65
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <map>

using namespace std;

int S(0),
	N(0),
	v[100];

int main(int argc, char *argv[]) {
	ifstream fin("loto.in");
	fin >> N >> S;
	for (int i(0); i < N; ++i)
		fin >> v[i];
	fin.close();

	map<int, vector<int> > sume;

	for (int i(0); i < N; ++i)	
		for (int j(0); j < N; ++j)
			for (int k(0); k < N; ++k)
				if (sume.count(v[i] + v[j] + v[k]) == 0) {
					vector<int> aux;
					aux.push_back(v[i]);
					aux.push_back(v[j]);
					aux.push_back(v[k]);
					sume.insert(pair<int, vector<int> >(v[i] + v[j] + v[k], aux));
				}

	for (map<int, vector<int> >::const_iterator it = sume.begin(); it != sume.end(); ++it)
		if (sume.count(S - it->first)) {
			ofstream fout("loto.out");
			vector<int> aux = sume[S - it->first];
			fout << it->second[0] << " " << it->second[1] << " " << it->second[2] << " "
				<< aux[0] << " " << aux[1] << " " << aux[2] << endl;
			fout.close();
			return 0;
		}

	ofstream fout("loto.out");
	fout << -1 << endl;
	fout.close();

	return 0;
}