Cod sursa(job #2745455)

Utilizator Dantelogus99Gruia Gabriel Dantelogus99 Data 26 aprilie 2021 16:04:53
Problema Loto Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;

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

class halfSum
{
public:
	int a;
	int b;
	int c;
};

unordered_map<int, halfSum> semiSume;
int v[100];
int n, s;
bool found = false;

int main()
{
	halfSum ob;
	fin >> n >> s;

	for (int i = 0; i < n; i++)
		fin >> v[i];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				ob.a = v[i];
				ob.b = v[j];
				ob.c = v[k];
				int suma = v[i] + v[j] + v[k];
				semiSume.insert({ suma, ob });

				auto comp = semiSume.find(s - suma);
				if (comp != semiSume.end())
				{
					found = true;
					fout << ob.a << " " << ob.b << " " << ob.c << " " << comp->second.a << " " << comp->second.b << " " << comp->second.c;
					return 0;
				}
			}
		}
	}

	if (!found)
		fout << -1;
}