Cod sursa(job #2745459)

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

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

struct halfSum
{
	int a;
	int b;
	int c;
};

unordered_map<int, halfSum> semiSume;
int v[100];

int n, s;
bool found = false;

int main()
{
	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++)
			{
				int suma = v[i] + v[j] + v[k];
				semiSume[suma].a = v[i];
				semiSume[suma].b = v[j];
				semiSume[suma].c = v[k];

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

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