Cod sursa(job #1923592)

Utilizator Wh1plashOvidiu Taralesca Wh1plash Data 11 martie 2017 17:41:46
Problema Loto Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#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;
}