Pagini recente » Cod sursa (job #126914) | Istoria paginii runda/simulare-cartita-06 | Profil cristy123 | Profil JohnLocke | Cod sursa (job #2746189)
#include <bits/stdc++.h>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int n, s;
vector<int> numere;
unordered_map<int, tuple<int, int, int>> suma;
int main()
{
in >> n >> s;
for(int i=0; i<n; i++)
{
int x;
in >> x;
numere.push_back(x);
}
for(int i=0; i<n; i++)
{
for(int j=i; j<n; j++)
{
for(int k=j; k<n; k++)
{
suma[numere[i] + numere[j] + numere[k]] = make_tuple(numere[i], numere[j], numere[k]);
}
}
}
bool ok = false;
unordered_map<int, tuple<int, int, int>>::iterator i;
for(i = suma.begin(); i != suma.end(); i++)
{
int rest = s - i->first;
if(suma.find(rest) != suma.end())
{
out << get<0>(i->second) <<' '<<get<1>(i->second)<<' '<<get<2>(i->second)<<' ';
out << get<0>(suma[rest]) <<' '<< get<1>(suma[rest])<<' ' << get<2>(suma[rest]);
ok = true;
break;
}
}
if (!ok)
out<<-1;
return 0;
}