Pagini recente » Cod sursa (job #3241167) | Cod sursa (job #933275) | Cod sursa (job #902919) | Cod sursa (job #985125) | Cod sursa (job #1441303)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
struct aaa
{
int f;
int a, b, c;
};
int a[101];
aaa b[100000];
bool c(aaa x,aaa y)
{
if (x.f < y.f)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
ifstream in("loto.in");
ofstream out("loto.out");
int i,s, n,j,tot=0,k,inceput,sfarsit,mij;
in >> n;
in >> s;
for (i = 1; i <= n; i++)
{
in >> a[i];
}
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++)
{
for (j = i; j <= n; j++)
{
for (k = j; j <= n; j++)
{
tot++;
b[tot].f = a[i] + a[j] + a[k];
b[tot].a = i;
b[tot].b = j;
b[tot].c = k;
}
}
}
sort(b + 1, b + tot + 1, c);
for (i = 1; i <= tot; i++)
{
inceput = 1;
sfarsit = tot;
while (inceput <= sfarsit)
{
mij = (inceput + sfarsit) / 2;
if (b[i].f + b[mij].f < s)
{
inceput = mij + 1;
}
else if (b[i].f + b[mij].f > s)
{
sfarsit = mij - 1;
}
else
{
out << b[i].a << " " << b[i].b << " " << b[i].c << " " << b[mij].a << " " << b[mij].b << " " << b[mij].c;
return 0;
}
}
}
out << "-1";
}