Pagini recente » Cod sursa (job #301621) | Cod sursa (job #1914112) | Cod sursa (job #1162152) | Cod sursa (job #2324842) | Cod sursa (job #2783550)
#include <iostream>
#include <unordered_map>
#include <fstream>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
pair <int , int> c;
pair <int, pair<int,int> > d;
unordered_map <int , pair<int , pair<int,int> > > H;
int main()
{
long long n,s,V[100],a = 1,ok = 0;
fin>>n>>s;
for(int i = 1;i<=n;i++)
{
fin>>V[i];
}
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
for(int k = 1;k<=n;k++)
{
c.first = V[j];
c.second = V[k];
d.first = V[i];
d.second = c;
H[V[i]+V[j]+V[k]] = d;
a++;
}
}
}
for(auto it: H)
{
if(H.find(s - it.first) != H.end())
{
ok = 1;
fout<<H[s - it.first].first<<' '<<H[s - it.first].second.first<<' '<<H[s - it.first].second.second<<' ';
fout<<it.second.first<<' '<<it.second.second.first<<' '<<it.second.second.second;
break;
}
}
if(ok == 0)
fout<<-1;
}