Pagini recente » Cod sursa (job #2879123) | Cod sursa (job #2530699) | Cod sursa (job #157618) | Cod sursa (job #3293582) | Cod sursa (job #3269489)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
const int SIZE = 105;
struct pereche
{
int a, b, c;
};
int n, S;
int a[SIZE];
bool exista_sol = false;
unordered_map<int, pereche> M;
multiset<int> sol;
int main()
{
fin >> n >> S;
for(int i = 1; i <= n; ++i)
fin >> a[i];
//luam fiecare pereche de triplete (i, j, k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k)
M[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
//caut un raspuns
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k)
{
int s = a[i] + a[j] + a[k];
if(S >= s)
if(M.find(S - s) != M.end())
{
exista_sol = true;
auto it = M.find(S - s);
sol.insert(a[i]);
sol.insert(a[j]);
sol.insert(a[k]);
sol.insert(it->second.a);
sol.insert(it->second.b);
sol.insert(it->second.c);
for(auto e : sol)
fout << e << " ";
return 0;
}
}
if(!exista_sol)
fout << -1;
return 0;
}