Pagini recente » Cod sursa (job #465080) | Cod sursa (job #2817720) | Cod sursa (job #1290974) | Cod sursa (job #224566) | Cod sursa (job #2740908)
#include <iostream>
#include <fstream>
#include <tuple>
#include <unordered_map>
using namespace std;
unordered_map<int, tuple<int,int,int>>hash_map;
int main()
{
int n,s;
tuple<int,int,int> t;
ifstream f("loto.in");
ofstream g("loto.out");
f >> n >> s;
int v[n];
for(int i = 0; i< n; i++)
f >> v[i];
for(int i = 0; i < n; i++){
for(int j = i; j< n; j++){
for(int p = j; p < n; p++){
t = make_tuple(v[i],v[j],v[p]);
hash_map[v[i] + v[j] + v[p]] = t;
}
}
}
int ok = 0;
for( auto i:hash_map){
int target = s - i.first;
if (hash_map.find(target) != hash_map.end()){ // daca target se afla in hash
ok = 1;
t = i.second;
g << get<0>(t) << " "<< get<1>(t) << " "<< get<2>(t)<<" ";
t = hash_map[target];
g << get<0>(t) << " "<< get<1>(t) << " "<< get<2>(t);
break;
}
}
if (ok == 0)
g << "-1";
f.close();
g.close();
return 0;
}