Cod sursa(job #69650)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 3 iulie 2007 20:03:10
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#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;
for (short i=n-1;i>=0;i--)
for (short j=n-1;j>=0;j--)
for (short k=n-1;k>=0;k--)
for (short l=n-1;l>=0;l--)
for (short o=n-1;o>=0;o--)     
   if (caut(T-a[i]-a[j]-a[k]-a[l]-a[o];)==1){
    fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[l]<<" "<<a[o]<<" "<<T-a[i]-a[j]-a[k]-a[l]-a[o];<<"\n";
    return 1;}
return 0;
}
int main(){
citire();
bule();
if (parc()==0)
  fout<<"-1";
return 0;
}