Cod sursa(job #1923596)

Utilizator Wh1plashOvidiu Taralesca Wh1plash Data 11 martie 2017 17:52:53
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 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;
}
void quick(int v[],int left,int right)
{
    int i=left,j=right,p=v[(left+right)/2],man;
    while(i<=j)
    {
        while(v[i]>p)i++;
        while(v[j]<p)j--;
        if(i<=j){man=v[i];v[i]=v[j];v[j]=man;i++;j--;}
    }
    if(left<j)quick(v,left,j);
    if(i<right)quick(v,i,right);
}
int main()
{
    in>>n>>p;
    for(i=1;i<=n;i++) in>>v[i];
    quick(v,1,n);
    for(a=1;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;
}