Pagini recente » Cod sursa (job #2241266) | Cod sursa (job #2474494) | Cod sursa (job #2901569) | Cod sursa (job #1583965) | Cod sursa (job #69249)
Cod sursa(job #69249)
#include<fstream.h>
long a[100],T,x;
ofstream fout("loto.out");
short n;
void citire(){
ifstream fin("loto.in");
fin>>n>>T;
for (short i=0;i<n;i++)
fin>>a[i];
fin.close();
}
void bule(){
short ok=0,p=n;
while(ok==0){
ok=1;
p--;
for (short i=0;i<p;i++)
if (a[i]>a[i+1]){
long aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
ok=0;}
}
}
int caut(long x){
int st=0,dr=n-1,m;
while (st<dr){
m=(st+dr)/2;
if (a[m]==x)
return 1;
else
if (a[m]<x)
st=m+1;
else dr=m-1;}
return 0;
}
int parc(){
long S;
short nr1=0,nr2=0,nr3=0,nr4=0,nr5=0,nr6=0;
short f=n-1;
while (a[f]*6>T){
nr1++;
f--;}
f=n-1;
while (a[f]*5>T){
nr2++;
f--;}
f=n-1;
while (a[f]*4>T){
nr3++;
f--;}
f=n-1;
while (a[f]*3>T){
nr4++;
f--;}
f=n-1;
while (a[f]*2>T){
nr5++;
f--;}
f=n-1;
while (a[f]*1>T){
nr6++;
f--;}
short nr=nr1+nr2+nr3+nr4+nr5+nr6;
nr=0;
for (short i=n-1-nr;i>=0;i--)
for (short j=n-1-nr;j>=0;j--)
for (short k=n-1-nr;k>=0;k--)
for (short l=n-1-nr;l>=0;l--)
for (short o=n-1-nr;o>=0;o--){
x=T-a[i]-a[j]-a[k]-a[l]-a[o];
if (caut(x)==1){
fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[l]<<" "<<a[o]<<" "<<x<<"\n";
return 1;}}
return 0;
}
int main(){
citire();
bule();
if (parc()==0)
fout<<"-1";
return 0;
}