Pagini recente » Cod sursa (job #2012861) | Cod sursa (job #2088386) | Cod sursa (job #2219130) | Cod sursa (job #2039528) | Cod sursa (job #2746894)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
struct pereche
{
int x, y, z;
}p;
int n,s;
int v[101];
unordered_map <int, pereche> H;
int main()
{
in >> n >> s;
for(int i=1; i<=n; i++)
in >> v[i];
for(int i=1; i<=n; i++)
for(int j=i; j<=n; j++)
for(int k=j; k<=n; k++)
{
p.x = v[i];
p.y = v[j];
p.z = v[k];
H[v[i]+v[j]+v[k]] = p;
}
int ok = 0;
for(auto it=H.begin(); it != H.end(); it++)
if(H.find(s-(*it).first) != H.end())
{
out << (*it).second.x << " " << (*it).second.y << " " << (*it).second.z << " ";
out << H[s-(*it).first].x << " " << H[s-(*it).first].y << " " << H[s-(*it).first].z;
ok = 1;
break;
}
if(ok == 0)
out << -1;
in.close();
out.close();
return 0;
}