Cod sursa(job #974371)

Utilizator smaraldaSmaranda Dinu smaralda Data 16 iulie 2013 22:47:11
Problema Loto Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

struct BILET
    {
        int b1,b2,b3,s;
    };
vector <BILET> sum;
BILET aux;
int b[110];

class cmp
     {
         public:
            bool inline operator () ( const BILET &a, const BILET &b)
                {
                    return a.s<b.s;
                }
     };
int main()
{
    freopen("loto.in","r",stdin);
    freopen("loto.out","w",stdout);
    int n,S,i,j,k,st,dr;
    scanf("%d%d",&n,&S);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);

    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            for(k=1;k<=n;k++)
                {
                    aux={b[i],b[j],b[k],b[i]+b[j]+b[k]};
                    sum.push_back(aux);
                }
    sort(sum.begin(),sum.end(),cmp());
    st=0; dr=sum.size()-1;
    while(st<=dr)
        {
            while(st<=dr && sum[st].s + sum[dr].s >= S)
                {
                    if(sum[st].s+sum[dr].s==S)
                        {
                            printf("%d %d %d %d %d %d",sum[st].b1,sum[st].b2,sum[st].b3,sum[dr].b1,sum[dr].b2,sum[dr].b3);
                            return 0;
                        }
                    dr--;
                }
            st++;
        }
    printf("-1\n");
    return 0;
}