Pagini recente » Cod sursa (job #522926) | Cod sursa (job #758156) | Cod sursa (job #927436) | Cod sursa (job #753062) | Cod sursa (job #2755717)
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> values;
int N, S;
ifstream cin("loto.in");
ofstream cout("loto.out");
bool checksol(){
unordered_map<int, vector<int>> hashmap;
unordered_map<int, vector<int>>::iterator it;
for(int i = 0; i < N; ++i)
for(int j = 0; j < N; ++j)
for(int k = 0; k < N; ++k){
int curr_sum = values[i] + values[j] + values[k];
hashmap.insert(pair<int, vector<int>>(curr_sum, {i, j, k}));
it = hashmap.find(S - curr_sum);
if(it != hashmap.end()){
cout << values[i] << " " << values[j] << " " << values[k] << " " << values[it->second[0]] << " " << values[it->second[1]] << " " << values[it->second[2]];
return true;
}
}
return false;
}
int main()
{
cin >> N >> S;
values.reserve(N);
for(int i = 0; i < N; ++i)
cin >> values[i];
bool amsol = checksol();
if(!amsol)
cout << -1;
cin.close();
cout.close();
return 0;
}