Cod sursa(job #813169)
#include <fstream>
using namespace std;
#define mod 999983
struct nod
{
int inf1, inf2, inf3;
nod *adr;
}*l[mod];
void add(int a, int b, int c)
{
const int m = (a+b+c)%mod;
if (!l[m])
{
l[m] = new nod;
l[m]->inf1 = a;
l[m]->inf2 = b;
l[m]->inf3 = c;
l[m]->adr = NULL;
}
}
int main()
{
ifstream in("loto.in"); ofstream out("loto.out");
int n, s, i, j, k, *v;
in>>n>>s;
v = new int[n];
for (i=0;i<n;i++) in>>v[i];
for (i=0;i<n;i++)
for (j=0;j<n;j++)
for (k=0;k<n;k++)
add(v[i], v[j], v[k]);
for (i=0;i<mod;i++)
if (l[i] && l[(s-i)%mod])
{
const int x = (s-i)%mod;
out<<l[i]->inf1<<" "<<l[i]->inf2<<" "<<l[i]->inf3<<" "<<l[x]->inf1<<" "<<l[x]->inf2<<" "<<l[x]->inf3;
return 0;
}
out<<-1;
return 0;
}