Pagini recente » Cod sursa (job #1608902) | Cod sursa (job #1675143) | Cod sursa (job #2789765) | Cod sursa (job #216148) | Cod sursa (job #1089018)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
#define MAX 102
int a[MAX];
int b[MAX*MAX*MAX];
int n,s;
int t;
int cautare(int s1)
{
int st=1,dr=t,m;
int x=s-s1;
while(st<=dr)
{
m=(st+dr)/2;
if(b[m]==x)
return m;
if(b[m]>x)
st=m+1;
else
dr=m-1;
}
return 0;
}
int main()
{
int i,j,k;
fin>>n>>s;
for(i=1;i<=n;i++)
fin>>a[i];
t=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++){
b[t]=a[i]+a[j]+a[k];
t++;
}
t--;
sort(b+1,b+t+1);
bool ok=0;
int x1,x2;
for(i=1;i<=t;i++){
j=cautare(b[i]);
if(j){
x1=i;
x2=j;
ok=1;
break;
}
}
if(ok)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++){
if(b[x1]==a[i]+a[j]+a[k]){
fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" ";
goto next;
}
}
next:
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++){
if(b[x2]==a[i]+a[j]+a[k]){
fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<"\n";
goto sebi;
}
}
sebi:;
}
else
fout<<-1<<"\n";
return 0;
}