Pagini recente » Cod sursa (job #753114) | Cod sursa (job #1802446) | Cod sursa (job #389367) | Cod sursa (job #971485) | Cod sursa (job #2783971)
#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;
pair <int, pair<int,int> > raspuns;
unordered_map <int , pair<int , pair<int,int> > > H;
int main()
{
long long n,s,V[100],a = 1;
fin>>n>>s;
for(int i = 1;i<=n;i++)
{
fin>>V[i];
}
for(int i = 1;i<=n;i++)
{
for(int j = i;j<=n;j++)
{
for(int k = j;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())
{
raspuns = H[s - it.first];
fout<<raspuns.first<<' '<<raspuns.second.first<<' '<<raspuns.second.second<<' ';
fout<<it.second.first<<' '<<it.second.second.first<<' '<<it.second.second.second;
return 0;
}
}
fout<<-1;
}