Cod sursa(job #2894672)

Utilizator widzAndrei-Daniel Tava widz Data 28 aprilie 2022 01:05:44
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;


int main()
{

	ifstream in("loto.in");
	ofstream out("loto.out");
	using uint = unsigned int;
	uint n, sum, nr;
	vector<uint> nrs;
	unordered_map<uint, pair<uint, uint>> sums;
	in >> n >> sum;
	for (uint i = 0; i < n; ++i)
	{
		in >> nr;
		nrs.push_back(nr);
	}
	in.close();

	for (auto nr1 : nrs)
		for (auto nr2 : nrs)
			for (auto nr3 : nrs)
				if (nr1 + nr2 + nr3 < sum)
					sums[nr1 + nr2 + nr3] = make_pair(nr1, nr2);

	for (const auto& parsum : sums)
	{
		const auto& diff = sums.find(sum - parsum.first);
		if (diff != sums.end())
		{
			out << parsum.second.first << " ";
			out << parsum.second.second << " ";
			out << parsum.first - parsum.second.first - parsum.second.second << " ";
			out << diff->second.first << " ";
			out << diff->second.second << " ";
			out << diff->first - diff->second.first - diff->second.second;
			out.close();
			return 0;
		}
	}
	out << -1;
	out.close();
	return 0;
}