Cod sursa(job #1232608)

Utilizator vladrochianVlad Rochian vladrochian Data 23 septembrie 2014 15:23:03
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <unordered_map>
using namespace std;

struct Triplet {
	int x, y, z;
	Triplet(int nx, int ny, int nz) {
		x = nx;
		y = ny;
		z = nz;
	}
};

int N, S, a[105];
unordered_map<int, Triplet> sum_map;

ifstream fin("loto.in");
ofstream fout("loto.out");

int main() {
	fin >> N >> S;
	for (int i = 0; i < N; ++i)
		fin >> a[i];
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < N; ++j)
			for (int k = 0; k < N; ++k) {
				int crt_sum = a[i] + a[j] + a[k];
				sum_map.insert(make_pair(crt_sum, Triplet(a[i], a[j], a[k])));
				auto it = sum_map.find(S - crt_sum);
				if (it != sum_map.end()) {
					fout << a[i] << " "
					     << a[j] << " "
					     << a[k] << " "
					     << it->second.x << " "
					     << it->second.y << " "
					     << it->second.z << "\n";
					return 0;
				}
			}
	fout << "-1\n";
	return 0;
}