Pagini recente » Cod sursa (job #527250) | Cod sursa (job #2779467) | Cod sursa (job #346233) | Cod sursa (job #2621774) | Cod sursa (job #2747878)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
struct valori
{
int x, y, z;
};
unordered_map <int, valori> hhash;
int main()
{
ifstream in("loto.in");
ofstream out("loto.out");
int v[101], n, s, ok = 0;
in >> n >> s;
for(int i = 0; i < n; i++)
in >> v[i];
//mapam valorile date (realizam sumele posibile)
for(int i = 0; i < n; i++)
for(int j = i; j < n; j++)
for(int k = j; k < n; k++)
hhash[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};
//parcurgem map-ul
for(auto i: hhash)
if(hhash.find(s-i.first) != hhash.end()) //in cazul in care gasim perechea lui s-i o afisam si ne oprim
{
out << hhash[s-i.first].x << " " << hhash[s-i.first].y << " " << hhash[s-i.first].z << " " << i.second.x << " " << i.second.y << " " << i.second.z;
ok = 1;
break; //cand am gasit o varianta ne oprim
}
if(!ok) //daca nu gasim nicio varianta afisam -1
out << "-1";
return 0;
}