Pagini recente » Cod sursa (job #2516513) | Cod sursa (job #258855) | Cod sursa (job #2357395) | Cod sursa (job #2633257) | Cod sursa (job #69367)
Cod sursa(job #69367)
#include<fstream>
using namespace std;
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 n){
int st=0,dr=n, 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;
for (short i=n-1;i>=0;i--)
for (short j=i;j>=0;j--)
for (short k=j;k>=0;k--)
for (short l=k;l>=0;l--)
for (short o=l;o>=0;o--){
x=T-a[i]-a[j]-a[k]-a[l]-a[o];
if (caut(x, o)){
fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[l]<<" "<<a[o]<<" "<<x<<"\n";
return 1;
}
}
return 0;
}
int main(){
citire();
bule();
if (!parc())
fout<<"-1";
fout.close();
return 0;
}