Pagini recente » Cod sursa (job #1240807) | Cod sursa (job #2812784) | Cod sursa (job #156277) | Cod sursa (job #2749612) | Cod sursa (job #2918109)
#include <bits/stdc++.h>
#define nmax 102
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int v[nmax];
int n,s;
int c[nmax*nmax*nmax];
int main()
{
f>>n>>s;
for(int i=0;i<n;i++)
{
f>>v[i];
}
//cout<<"here\n";
int n3=n*n*n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
c[i+j*n+k*n*n]=v[i]+v[j]+v[k];
}
}
}
//cout<<"here\n";
sort(c,c+n3);
int a=0,b=n3-1;
bool ok=0;
for(;a<n3&&a<=b;a++)
{
while(c[a]+c[b]>s) b--;
if(c[a]+c[b]==s)
{
ok=1;
break;
}
}
//cout<<"here\n";
if(!ok)
{
g<<-1;
return 0;
}
bool low=0,up=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
if(!low&&v[i]+v[j]+v[k]==c[a])
{
low=1;
g<<v[i]<<' '<<v[j]<<' '<<v[k]<<' ';
}
else if(!up&&v[i]+v[j]+v[k]==c[b])
{
up=1;
g<<v[i]<<' '<<v[j]<<' '<<v[k]<<' ';
}
if(low&&up)
{
return 0;
}
}
}
}
//cout<<"here\n";
return 0;
}