Cod sursa(job #2553102)

Utilizator Codrut112Codrut Copas Codrut112 Data 21 februarie 2020 16:54:42
Problema Loto Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct loto
{
    int suma;
    int i,j,l;
};
bool comp(loto a,loto b)
{
    return a.suma<b.suma;

}
loto v[1000001];
int n,s,i,j,l,x,ok,k,w[101],nr,u[7];
int main()
{
    f>>n;
    f>>s;
    for(i=1; i<=n; i++)

        f>>w[i];


    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            for(l=1; l<=n; l++)
            {
                nr++;
                v[nr].suma=w[i]+w[j]+w[l];
                v[nr].i=i;
                v[nr].j=j;
                v[nr].l=l;
            }
    sort(v+1,v+nr+1,comp);

    for(i=1; i<=nr; i++)
    {if(ok==1) break;
        for(j=nr; j>=1; j--)if(v[i].suma+v[j].suma==s)
            {
                u[1]=w[v[i].i];
                u[2]=w[v[i].j];
                u[3]=w[v[i].l];
                u[4]=w[v[j].i];
                u[5]=w[v[j].j];
                u[6]=w[v[j].l];
                sort(u+1,u+6+1);
                for(l=1; l<=6; l++)g<<u[l]<<" ";
                ok=1;
            }


    }

}