Pagini recente » Cod sursa (job #2257392) | Cod sursa (job #443187) | Cod sursa (job #541100) | Cod sursa (job #2547684) | Cod sursa (job #1923592)
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
int i, n, p, a,b,c,d,e,f, v[101];
ifstream in("loto.in");
ofstream out("loto.out");
bool comp(int a, int b){
if(b>a) return false;
return true;
}
int main()
{
in>>n>>p;
for(i=0;i<n;i++) in>>v[i];
sort(v,v+n, comp);
for(a=0;a<n && v[a]*6>=p;a++)
for(b=a;b<n && v[a]+v[b]*5>=p && v[a]+v[n]*5<=p;b++)
for(c=b;c<n && v[a]+v[b]+v[c]*4>=p && v[a]+v[b]+v[n]*4<=p;c++)
for(d=c;d<n && v[a]+v[b]+v[c]+v[d]*3>=p && v[a]+v[b]+v[c]+v[n]*3<=p;d++)
for(e=d;e<n && v[a]+v[b]+v[c]+v[d]+v[e]*2>=p && v[a]+v[b]+v[c]+v[d]+v[n]*2<=p;e++)
for(f=e;f<n && v[a]+v[b]+v[c]+v[d]+v[e]+v[f]>=p;f++)
{
if(v[a]+v[b]+v[c]+v[d]+v[e]+v[f]==p)
{
out<<v[a]<<' '<<v[b]<<' '<<v[c]<<' '<<v[d]<<' '<<v[e]<<' '<<v[f];
return 0;
}
}
out<<-1;
return 0;
}