Pagini recente » Cod sursa (job #626210) | Cod sursa (job #2899099) | Cod sursa (job #950740) | Cod sursa (job #2712547) | Cod sursa (job #2703185)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct tri
{
int a,b,c,sum;
};
int n,s,nr;
tri three[1000010];
int v[102];
bool comp(tri x, tri y)
{
return x.sum<y.sum;
}
int main()
{
fin>>n>>s;
for(int i=0; i<n; i++)
{
fin>>v[i];
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
for(int k=0; k<n; k++)
{
three[nr].sum=v[i]+v[j]+v[k];
three[nr].a=v[i];
three[nr].b=v[j];
three[nr++].c=v[k];
}
}
}
sort(three, three+nr, comp);
for(int i=0; i<nr; i++)
{
int target = s - three[i].sum;
int st=0;
int dr=nr-1;
int res =0;
while(st<=dr)
{
int mij=(st+dr)/2;
if(three[mij].sum == target)
{
res=mij;
break;
}
else if(three[mij].sum<target)
{
st=mij+1;
}
else dr=mij-1;
}
if(target == three[res].sum)
{
fout<<three[i].a<<" "<<three[i].b<<" "<<three[i].c<<" "
<<three[res].a<<" "<<three[res].b<<" "<<three[res].c;
return 0;
}
}
fout<<"-1";
return 0;
}