Cod sursa(job #1573362)

Utilizator krityxAdrian Buzea krityx Data 19 ianuarie 2016 17:29:04
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <unordered_map>
#include <algorithm>

using namespace std;

struct triplet
{
	int a, b, c;
	triplet(int x, int y, int z)
	{
		a = x;
		b = y;
		c = z;
	}
	triplet()
	{
		a = b = c = 0;
	}
};

bool cmp(int a, int b)
{
	return a > b;
}

int main()
{
	int N, S, V[102], i, j, k, tmpSum;
	unordered_map<int, triplet> m;
	ifstream f("loto.in");
	f >> N >> S;
	for (i = 1; i <= N; i++)
	{
		f >> V[i];
	}
	f.close();
	sort(begin(V) + 1, begin(V) + N + 1);
	for (i = 1; i <= N; i++)
	{
		for (j = i; j <= N; j++)
		{
			for (k = j; k <= N; k++)
			{
				tmpSum = V[i] + V[j] + V[k];
				triplet t(i, j, k);
				m[tmpSum] = t;
			}
		}
	}
	ofstream g("loto.out");
	for (i = 1; i <= N; i++)
	{
		for (j = i; j <= N; j++)
		{
			for (k = j; k <= N; k++)
			{
				tmpSum = S - (V[i] + V[j] + V[k]);
				triplet t = m[tmpSum];
				if (t.a)
				{
					g << V[i] << " " << V[j] << " " << V[k] << " " << V[t.a] << " " << V[t.b] << " " << V[t.c];
					return 0;
				}
			}
		}
	}
	g << -1;
	g.close();
	return 0;
}