Cod sursa(job #2746810)

Utilizator vladalex420@gmail.comLuta Vlad Alexandru [email protected] Data 28 aprilie 2021 15:39:27
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <unordered_map>

struct Vals
{
	int a, b, c;
};

int main()
{

	std::ifstream f("loto.in");
	int n, s;
	f >> n >> s;
	std::vector<int> valori;
	valori.reserve(n);

	for(int i=0;i<n;i++)
	{
		int val;
		f >> val;
		valori.push_back(val);
	}
	f.close();

	std::unordered_map<int, Vals> sume;

	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++)
			for (int k = j; k < n; k++)
			{
				sume[valori[i] + valori[j] + valori[k]] = { valori[i],valori[j],valori[k] };
			}

	std::ofstream out("loto.out");

	for(auto i: sume)
	{
		int otherVal = s - i.first;

		auto f = sume.find(otherVal);

		if(f != sume.end())
		{
			out << i.second.a << " " << i.second.b << " " << i.second.c << " " <<
				f->second.a << " " << f->second.b << " " << f->second.c;
			out.close();

			return 0;
		}
	}


	out << -1;
	out.close();

	return 0;
}