Pagini recente » Cod sursa (job #1216062) | Cod sursa (job #2397529) | Cod sursa (job #1632528) | Cod sursa (job #2366912) | Cod sursa (job #1187099)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct art { int s,a,b,c; } V[1000009];
int n,sum,nr,A[109];
int cmp(art x, art y)
{
return (x.s < y.s);
}
int main()
{
fin >> n >> sum;
for(int i=1; i<=n; i++) fin >> A[i];
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
for(int k=1; k<=n; k++)
{
V[++nr].s = A[i] + A[j] + A[k];
V[nr].a = A[i];
V[nr].b = A[j];
V[nr].c = A[k];
}
}
}
sort(V+1, V+1+nr, cmp);
int w = 1;
for(int i=1; i<=nr && w; i++)
{
int sumcaut = sum - V[i].s, st = 1, dr = nr;
while(st <= dr && w)
{
int mij = (st+dr) / 2;
if(V[mij].s < sumcaut) dr = mij - 1;
else if(V[mij].s > sumcaut) st = mij + 1;
else
{
w = 0;
fout << V[i].a << ' ' << V[i].b << ' ' << V[i].c << ' ';
fout << V[mij].a << ' ' << V[mij].b << ' ' << V[mij].c << '\n';
}
}
}
if(w) fout << "-1\n";
fout.close();
return 0;
}