Pagini recente » Cod sursa (job #2200912) | Cod sursa (job #2379830) | Cod sursa (job #2392068) | Cod sursa (job #2279763) | Cod sursa (job #3139544)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
unordered_map<int, vector<int>> solve;
int n;
int loto[100];
int s,rest,sum;
bool gasit = false;
int main()
{
in>>n>>s;
for(int i=1;i<=n;i++)
in >> loto[i];
for(int i=1;i<=n&&gasit!=true;i++)
{
for(int j=1;j<=n && gasit!=true;j++)
{
for (int k=1;k<=n&&gasit!=true;k++)
{
sum=loto[i]+loto[j]+loto[k];
solve[sum]={loto[i], loto[j], loto[k]};
rest=s-sum;
if (solve.count(rest))
{
out<<solve[sum][0]<<" "<<solve[sum][1]<<" "<<solve[sum][2]<<" "<<solve[rest][0]<<" "<<solve[rest][1]<<" "<<solve[rest][2];
gasit=true;
}
}
}
}
if (gasit==0)
out<<-1;
return 0;
}