Pagini recente » Cod sursa (job #561085) | Cod sursa (job #234079) | Cod sursa (job #1662741) | Cod sursa (job #2042503) | Cod sursa (job #2755740)
#include <fstream>
#include <vector>
#include <unordered_map>
#include <algorithm>
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];
if(curr_sum < S)
{
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;
}
}
else return false;
}
return false;
}
int main()
{
cin >> N >> S;
values.reserve(N);
for(int i = 0; i < N; ++i)
cin >> values[i];
sort(values.begin(), values.end());
bool amsol = checksol();
if(!amsol)
cout << -1;
cin.close();
cout.close();
return 0;
}