Pagini recente » Cod sursa (job #2212360) | Cod sursa (job #2535036) | Cod sursa (job #2415955) | Cod sursa (job #884143) | Cod sursa (job #151304)
Cod sursa(job #151304)
#include<fstream>
using namespace std;
long a[100],T;
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 parc(){
for (short i = 0; i < n; i++) {
long s = a[i];
if (s > T)
continue;
for (short j = i; j < n; j++) {
long s1 = s + a[j];
if (s1 > T)
continue;
for (short k = j; k < n; k++) {
long s2 = s + a[k];
if (s2 > T)
continue;
for (short l = k; l < n; l++) {
long s3 = s + a[l];
if (s3 > T)
continue;
for (short o = l; o < n; o++) {
long x = T - s3 - a[o];
if (x >= 0 && x <=a[o])
for (short p = o ; p < n; p++)
if ( x == a[p]){
fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<a[l]<<" "<<a[o]<<" "<<x<<"\n";
return 1;
}
}
}
}
}
}
return 0;
}
int main(){
citire();
bule();
if (a[n-1] > T || !parc())
fout<<"-1";
fout.close();
return 0;
}