Pagini recente » Cod sursa (job #624029) | Cod sursa (job #1654627) | Cod sursa (job #775736) | Cod sursa (job #1985289) | Cod sursa (job #2703188)
#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=1; i<=n; i++)
{
fin>>v[i];
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
for(int k=1; 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+1, three+nr+1, comp);
for(int i=1; i<=nr; i++)
{
int target = s - three[i].sum;
int st=1;
int dr=nr;
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;
}