Cod sursa(job #130518)

Utilizator scvalexAlexandru Scvortov scvalex Data 1 februarie 2008 13:52:03
Problema Loto Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <map>

using namespace std;

class ThreeTuple {
public:
	int v[3];
};

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, ThreeTuple> sume;

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

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

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

	return 0;
}