Cod sursa(job #2738167)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 5 aprilie 2021 15:27:06
Problema Loto Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
//Ilie Dumitru
#include<cstdio>
#include<algorithm>

struct suma
{
    int a, b, c, s;

    bool operator<(suma other)
    {
        return this->s<other.s;
    }
};

int v[100], n;
suma sume[1000005];

int main()
{
    freopen("loto.in", "r", stdin);
    freopen("loto.out", "w", stdout);
    int N, P, i, j, k;
    scanf("%d%d", &N, &P);
    for(i=0;i<N;++i)
        scanf("%d", v+i);
    fclose(stdin);
    for(i=0;i<N;++i)
        for(j=0;j<N;++j)
            for(k=0;k<N;++k)
                sume[n++]={v[i], v[j], v[k], v[i]+v[j]+v[k]};
    std::sort(sume, sume+n);
    for(i=0, j=n-1;i<n && j>-1;++i)
    {
        while(sume[i].s+sume[j].s>P)
            --j;
        if(sume[i].s+sume[j].s==P)
            printf("%d %d %d %d %d %d\n", sume[i].a, sume[i].b, sume[i].c, sume[j].a, sume[j].b, sume[j].c), i=n;
    }
    if(i==n)
        printf("-1");
    fclose(stdout);
    return 0;
}