Pagini recente » Profil MariaMMM09 | Rating Griffin (Griffin) | Cod sursa (job #1264108) | Statistici bibere corina (bibere_crn) | Cod sursa (job #1706223)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int n, v[101], nr;
long S;
typedef struct
{
int a, b, c;
long s;
}STR;
STR sum[1000001];
void citire()
{
in >> n >> S;
for (int i=1; i<=n; i++)
in >> v[i];
}
void calc()
{
int suma;
nr=0;
for (int i=1; i<=n; i++)
for (int j=i; j<=n; j++)
for (int k=j; k<=n; k++)
{
suma=v[i]+v[j]+v[k];
nr++;
sum[nr].s=suma;
sum[nr].a=i;
sum[nr].b=j;
sum[nr].c=k;
}
}
int cmp(STR a,STR b)
{
if (a.s < b.s)return 1;
return 0;
}
void afis(STR x, STR y)
{
out << v[x.a] << " " << v[x.b] << " " << v[x.c] << " " << v[y.a] << " " << v[y.b] << " " << v[y.c];
}
void cbin()
{
int i, j;
long s1, s2;
i=1;
j=nr;
while (i<=j)
{
s1=sum[i].s;
s2=S-sum[i].s;
while (i<=j&&sum[j].s>s2)
j--;
if (i>j)
{
out << -1;
break;
}
if (sum[j].s!=s2)
{
i++;
continue;
}
afis(sum[i], sum[j]);
break;
}
if (i>j)
out << -1;
}
int main()
{
citire();
calc();
sort(sum+1, sum+nr+1, cmp);
cbin();
in.close();
out.close();
return 0;
}