Pagini recente » Cod sursa (job #3032400) | Cod sursa (job #669429) | Cod sursa (job #1591236) | Cod sursa (job #2691045) | Cod sursa (job #3128594)
#include <iostream>
#include <fstream>
#include <unordered_set>
#include <vector>
#include <algorithm>
using namespace std;
bool gaseste_combinatie(int N, int S, vector<int> &numere, vector<int> &combinatie) {
for (int a = 0; a < N; ++a) {
for (int b = 0; b < N; ++b) {
for (int c = 0; c < N; ++c) {
for (int d = 0; d < N; ++d) {
for (int e = 0; e < N; ++e) {
for (int f = 0; f < N; ++f) {
if (numere[a] + numere[b] + numere[c] + numere[d] + numere[e] + numere[f] == S) {
combinatie = {numere[a], numere[b], numere[c], numere[d], numere[e], numere[f]};
return true;
}
}
}
}
}
}
}
return false;
}
int main() {
int N, S;
ifstream fin("loto.in");
ofstream fout("loto.out");
fin >> N >> S;
vector<int> numere(N);
for (int i = 0; i < N; ++i) {
fin >> numere[i];
}
vector<int> combinatie;
if (gaseste_combinatie(N, S, numere, combinatie)) {
for (int i = 0; i < 6; ++i) {
fout << combinatie[i] << ' ';
}
} else {
fout << -1;
}
fin.close();
fout.close();
return 0;
}