Cod sursa(job #3209773)

Utilizator Sebi_RipaSebastian Ripa Sebi_Ripa Data 3 martie 2024 15:02:59
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 (s > sum)
		return;
	if (nre == 6) {
		if (s == sum) {
			for (auto x : ans)
				cout << x << ' ';
			exit(0);
		}
		return;
	}
	if (pz > n)
		return;
	for (int i = 0; i <= 6; i++) {
		for (int j = 1; j <= i; j++)
			ans.push_back(v[pz]);
		bkt(n, s + v[pz] * i, nre + i, pz + 1);
		for (int j = 1; j <= i; j++)
			ans.pop_back();
	}
}

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