Cod sursa(job #3209772)

Utilizator Sebi_RipaSebastian Ripa Sebi_Ripa Data 3 martie 2024 14:53:48
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream cin("loto.in");
ofstream cout("loto.out");

int v[605], sum;
vector <int> ans;

void bkt(int n, int s, int nre, int pz) {
	if (nre == 6) {
		if (s == sum) {
			for (auto x : ans)
				cout << x << ' ';
			exit(0);
		}
		return;
	}
	if (pz == n * 6 + 1)
		return;
	ans.push_back(v[pz]);
	bkt(n, s + v[pz], nre + 1, pz + 1);
	ans.pop_back();
	bkt(n, s, nre, pz + 1);
}

int main() {
	int n;
	cin >> n >> sum;
	for (int i = 1; i <= n; i++) {
		cin >> v[(i - 1) * 6 + 1];
		for (int j = (i - 1) * 6 + 2; j <= i * 6; j++)
			v[j] = v[(i - 1) * 6 + 1];
	}
	bkt(n, 0, 0, 1);
	cout << -1;
}