Cod sursa(job #2776475)

Utilizator LaurentiuGradGrad Laurentiu LaurentiuGrad Data 19 septembrie 2021 22:17:16
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

int n, S;
int A[101];
int T[10];

void Back(int k, int s)
{
	if (k == 6)
	{
		if (s == S)
		{
			for (int i = 6; i >= 1; i--)
				fout << T[i] << ' ';
			fin.close();
			fout.close();
			exit(0);
		}
	}
	else
		for (int i = n; i >= 1; i--)
		{
			T[k + 1] = A[i];
			if (s <= S)
				Back(k + 1, s + A[i]);
		}
}

int main()
{
	fin >> n >> S;
	for (int i = 1; i <= n; i++)
		fin >> A[i];
	sort(A + 1, A + n + 1);
	Back(0, 0);
	fout << -1;
	fin.close();
	fout.close();
	return 0;
}