Cod sursa(job #2894446)

Utilizator widzAndrei-Daniel Tava widz Data 27 aprilie 2022 20:36:16
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 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)
				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;
}