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