Pagini recente » Cod sursa (job #2845503) | Cod sursa (job #14549) | Cod sursa (job #2088640) | Cod sursa (job #2591712) | Cod sursa (job #779837)
Cod sursa(job #779837)
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
int n, s, a[101], j, i, k, sum, r[7];
bool ok=false;
ifstream f("loto.in");
ofstream g("loto.out");
f>>n>>s;
for(i=1; i<=n; i++)
{
f>>a[i];
}
sort(a+1, a+n+1);
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
for(k=1; k<=n; k++)
{
sum=a[i]+a[j]+a[k];
r[1]=a[i];
r[2]=a[j];
r[3]=a[k];
int z;
for(z=4; z<=6; z++)
{
int lb=lower_bound(a+1, a+n+1, (s-sum)/(6-z+1))-a;
/*if(a[lb]<(s-sum)/(6-z+1))
lb--;*/
r[z]=a[lb];
sum+=r[z];
}
if(sum==s)
{
ok=true;
break;
}
}
if(ok) break;
}
if(ok)
break;
}
if(ok)
{
for(i=1; i<=6; i++)
{
g<<r[i]<<" ";
}
}
else
g<<-1;
}