Cod sursa(job #3163221)

Utilizator David2007David Preda David2007 Data 30 octombrie 2023 23:02:12
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("loto.in");
ofstream g("loto.out");

int i,j,n,m,l,s;
int w[105];

struct trei{
int x1,x2,x3;
};

unordered_map<int,trei> v;

int main()
{
    f>>n>>m;
    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++)
            {
                s=w[i]+w[j]+w[l];
                v[s].x1=w[i];
                v[s].x2=w[j];
                v[s].x3=w[l];
            }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            for(l=1;l<=n;l++)
            {
                s=m-(w[i]+w[j]+w[l]);
                if(v.find(s)!=v.end())
                {
                    g<<w[i]<<" "<<w[j]<<" "<<w[l]<<" "<<v[s].x1<<" "<<v[s].x2<<" "<<v[s].x3;
                    return 0;
                }
            }

    g<<-1;
}