Pagini recente » Cod sursa (job #897928) | Cod sursa (job #2321252) | Cod sursa (job #15958) | Cod sursa (job #1949857) | Cod sursa (job #2896010)
#include <bits/stdc++.h>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int main() {
int n,s,i,suma,j,q,v[101],ok=0;
unordered_map <int, tuple <int,int,int> > M;
tuple<int,int,int>t;
in>>n>>s;
for(i=0;i<n;i++)
in>>v[i];
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(q=j;q<n;q++)
{
suma = v[i]+v[j]+v[q];
M[suma]=make_tuple(v[i],v[j],v[q]);
}
}
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(q=j;q<n;q++)
{
int d = s-v[i]-v[j]-v[q];
if(M.find(d) != M.end())
{
t = M[d];
out<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<" "<<v[i]<<" "<<v[j]<<" "<<v[q]<<" ";
ok=1;
break;
}
}
if(ok==1)
break;
}
if(ok==1)
break;
}
if(ok==0){
out<<"-1";
}
return 0;
}