Pagini recente » Cod sursa (job #1032009) | Cod sursa (job #578916) | Cod sursa (job #1945447) | Cod sursa (job #1814074) | Cod sursa (job #720086)
Cod sursa(job #720086)
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef struct{
int x,y,z,q;
}loto;
loto s[1002];
int a[1011],m,i,j,k,S,max1,n,st,mij,dr,poz,tt;
bool ok;
double t;
bool cmp(loto a,loto b){
return(a.x<b.x);
}
int main(){
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
scanf("%d %d",&n,&S);
for (i=1; i<=n; ++i){
scanf("%d",&a[i]);
if (a[i]>max1) max1=a[i];
}
ok=true;
t=double (1.0*S/6);
if (t>max1){
ok=false;
printf("-1");
}
if (ok==true){
for (i=1; i<=n; ++i){
for (j=i; j<=n; ++j){
for (k=j; k<=n; ++k){
m++;
s[m].x=a[i]+a[j]+a[k];
s[m].y=a[i];
s[m].z=a[j];
s[m].q=a[k];
}
}
}
sort(s,s+m,cmp);
for (i=m; i>=1; --i){
tt=S-s[i].x;
poz=i;
st=1;
dr=m;
mij=(st+dr)/2;
ok=false;
while (ok==false && st<dr){
if (s[mij].x==tt){
ok=true;
printf("%d %d %d %d %d %d\n",s[poz].y,s[poz].z,s[poz].q,s[mij].y,s[mij].z,s[mij].q);
}
else if (s[mij].x>tt){
st=mij+1;
dr=m;
mij=(st+dr)/2;
}
else if (s[mij].x<tt){
st=1;
dr=mij-1;
mij=(st+dr)/2;
}
}
if (ok==true) break;
}
}
return(0);
}